当前位置: 代码迷 >> Iphone >> 新手提问,关于Exception的有关问题
  详细解决方案

新手提问,关于Exception的有关问题

热度:45   发布时间:2016-04-25 06:11:28.0
新手提问,关于Exception的问题
本帖最后由 z550946941 于 2012-12-20 16:33:01 编辑
这是一本关于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){
  相关解决方案