Can You Really Be Your Own Grandpa? (Inheritance problem)
Can You Really Be Your Own Grandpa? (Inheritance problem)
- Subject: Can You Really Be Your Own Grandpa? (Inheritance problem)
- From: email@hidden
- Date: Wed, 24 Jul 2002 19:56:24 -0400
I subclassed NSDictionary to create OrderedDictionary (which is a
dictionary that keeps the keys in the order they are recorded) and then
I subclassed OrderedDictionary to produce MutableOrderedDictionary. So:
NSDictionary->OrderedDictionary->MutableOrderedDictionary
As would be expected, this code:
void doSomethingToADictionary(NSMutableDictionary* mutableDict)
{
...
}
MutableOrderedDictionary* dict = [MutableOrderedDictionary dictionary];
doSomethingToADictionary(dict);
causes this error:
type `NSMutableDictionary' is not a base type for type
`MutableOrderedDictionary'
BUT this is the kicker (unless I am missing something): this following
code does work when it still shouldn't, since NSDictionary doesn't
inherit from NSMutableDictionary:
void doSomethingToADictionary(NSMutableDictionary* mutableDict)
{
...
}
NSDictionary* dict = [MutableOrderedDictionary dictionary]; //dict, of course,
really //represents a //MutableOrderedDictionary
doSomethingToADictionary(dict);
Why does this work?
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.