Confusing problems with inheritance in Objective-C
Confusing problems with inheritance in Objective-C
- Subject: Confusing problems with inheritance in Objective-C
- From: Darren Ford <email@hidden>
- Date: Tue, 22 Jun 2004 12:31:58 +1000
Hey all,
I've been having some problems trying to implement inheritance using
Objective-C (more specifically, attempting to create a class that
inherits from NSMutableDictionary).
What I'm finding is that when one of my methods (for example, the
'setDate' function below), that when it attempts to call the super's
method, I get the error :-
-setObject:forKey: only defined for abstract class. Define
-[MyInheritedDictionaryClass setObject:forKey:]'
Isn't NSMutableDictionary a concrete class (ie. I can instantiate one
using alloc/init?)
I've been programming in C++ for many years now, and I think the
problem is probably that I haven't fully understood the Obj-C concept
of inheritance and I'm trying to use my C++ knowledge to define my
class. Can anyone shed any light on why I'm seeing this problem? I've
attached my class definitions to the end of the email.
Cheers and thanks -- Darren.
---------- header
@interface MyInheritedDictionaryClass : NSMutableDictionary
- (NSDate *)theDate;
- (void)setTheDate:(NSDate *)newTheDate;
- (NSMutableArray *)theFiles;
- (void)setTheFiles:(NSMutableArray *)newTheFiles;
@end
---------- source
@implementation MyInheritedDictionaryClass
- (id) init
{
return [super init];
}
-(void) dealloc
{
[super dealloc];
}
- (NSDate *)theDate
{
return [super objectForKey:@"date"];
}
- (void)setTheDate:(NSDate *)newTheDate
{
[super setObject:newTheDate forKey:@"date"];
}
- (NSMutableArray *)theFiles
{
return [super objectForKey:@"files"];
}
- (void)setTheFiles:(NSMutableArray *)newTheFiles
{
[super setObject:newTheFiles forKey:@"files"];
}
@end
_______________________________________________
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.