Re: Adding a method makes a class abstract?
Re: Adding a method makes a class abstract?
- Subject: Re: Adding a method makes a class abstract?
- From: Marco Binder <email@hidden>
- Date: Mon, 17 Mar 2003 12:48:32 +0100
NSNumber is a class cluster. Therefore, some requirements apply when
subclassing: read the docs at NSNumber->Class Description-> Subclassing
NSNumber
It s probably more than you would want to invest just to make
description return the int value...
marco
Am Montag, 17.03.03 um 12:27 Uhr schrieb Mark Patterson:
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.
--
|\ /| E-Mail: email@hidden WWW: www.marco-binder.de
| \/ | Telefon: 07531 / 94 19 94 Fax: 07531 / 94 19 92
| |ARCO Snail-Mail: Banater Str. 3 - 78467 Konstanz
BINDER _____________________________________________________
_______________________________________________
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.