Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Can You Really Be Your Own Grandpa? (Inheritance problem)



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.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.