Adding a method makes a class abstract?
Adding a method makes a class abstract?
- Subject: Adding a method makes a class abstract?
- From: Mark Patterson <email@hidden>
- Date: Mon, 17 Mar 2003 21:27:19 +1000
Hi,
I'm going through the Hillegass book, and thought I'd try to change the
class used in one of the earlier exercises. So I subclassed NSNumber,
and when I ran it a line that worked with an instance of NSNumber gave
me an abstract object exception. Very strange from my Java / Delphi
point of view.
The code is:
#import <Foundation/Foundation.h>
@interface SimpleNumber: NSNumber {
}
- (NSString *)description;
@end
@implementation SimpleNumber
- (NSString *)description
{
return [[NSString alloc] initWithFormat:@"%d", [self intValue]];
}
@end
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSMutableArray * array;
int i;
NSNumber * number;
array = [[NSMutableArray alloc] init];
for (i = 0; i < 10; i++) {
number = [[SimpleNumber alloc] initWithInt:(i*3)];
[array addObject:number];
[number release];
}
NSLog(@"array=%@", array);
[array release];
[pool release];
return 0;
}
The error message is:
2003-03-17 19:24:01.779 lottery[464] *** Uncaught exception:
<NSInvalidArgumentException> *** initialization method -initWithInt:
cannot be sent to an abstract object of class SimpleNumber: Create a
concrete instance!
lottery has exited due to signal 5 (SIGTRAP).
Can anyone explain this for someone used to other OO environments?
Regards,
Mark
_______________________________________________
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.