这是一本关于Objective-c的书中的例子,使用CodeBlocks编译运行,出现以下错误:
Uncaught exception NSInvalidArgumentException, reason: NSAutoreleasePool(instance) does not recognize length
各位大神看看又啥不对的地方
代码如下:
#import <Foundation/Foundation.h>
//----------------------------------------
@interface Tire : NSObject
@end //Tire
@implementation Tire
- (NSString *) description{
return (@"I am a tire. I last a while.");
}//description
@end//Tire
//----------------------------------------
@interface AllWeatherRadial : Tire
@end //AllWeatherRadial
@implementation AllWeatherRadial
-(NSString *) description{
return (@"i am a tire for rain or shine.");
}
@end
//----------------------------------------
@interface Engine : NSObject
@end//Engine
@implementation Engine
-(NSString *) description{
return (@"I am an engine, Vrooom!");
}//description
@end //Engine
//----------------------------------------
@interface Slant6 : Engine
@end // Slant6
@implementation Slant6
-(NSString *) description{
NSLog(@"I am a slant-6. VROOOM!");
}
@end //Slant6
//----------------------------------------
@interface Car : NSObject{
Engine *engine;
Tire *tires[4];
}
-(Engine *) engine;
-(void) setEngine: (Engine *) newEngine;
-(Tire *) tireAtIndex: (int) index;
-(void) setTire: (Tire *) tire atIndex:(int) index;
-(void) print;
@end //Car
@implementation Car
-(id) init{
if(self == [super init]){
engine = [Engine new];
tires[0] = [Tire new];
tires[1] = [Tire new];
tires[2] = [Tire new];
tires[3] = [Tire new];
}
return self;
}
-(Engine *)engine{
return engine;
}
-(void) setEngine:(Engine *) newEngine{
engine = newEngine;
}
-(Tire *) tireAtIndex:(int) index{
if(index < 0 || index >3){
NSLog(@"bad index (%d) in tireAtIndex", index);
exit(1);
}
return tires[index];
}
-(void) setTire:(Tire *) tire atIndex:(int) index{
if(index < 0 || index >3){