• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Adding a method makes a class abstract?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Adding a method makes a class abstract?
      • From: Thomas Lachand-Robert <email@hidden>
    • Re: Adding a method makes a class abstract?
      • From: Marco Binder <email@hidden>
  • Prev by Date: Re: How To: Date/Time Field/Steppers
  • Next by Date: Re: Java vs C/Objective-C performance question
  • Previous by thread: Re: setting myself as fieldeditor's delegate?
  • Next by thread: Re: Adding a method makes a class abstract?
  • Index(es):
    • Date
    • Thread