构建失败:预期的标识符错误

时间:2013-08-17 20:30:14

标签: objective-c

您好我正在尝试学习Objective C,我尝试编写与教程相同的代码,但我无法运行该程序。

它表示NSAutoreleasePool * pool= [[NSAutoreleasePool alloc]];的预期标识符 我的代码中缺少什么?

    #import <Foundation/Foundation.h>

    @interface Person : NSObject
    {
        int age;
        int weight;
    }
    -(void) print;
    -(void) setAge : (int) a;
    -(void) setWeight : (int) w;
    @end

    @implementation Person

    -(void) print{

        NSLog(@"His name is %i and his weight is %i" , age, weight);

    }
    -(void) setAge:(int)a {
        age = a;

    }
    -(void) setWeight:(int)w {
        weight=w;

    }

    @end

    int main(int argc, const char * argv[])
    {

        NSAutoreleasePool * pool= [[NSAutoreleasePool alloc]];
        Person *person;

        person = [Person alloc];
        person = [person init];

        [person  setAge : 24];
        [person setWeight:90];

        [person print];
        [person release];
        [pool drain];
        return  0;
}


}

1 个答案:

答案 0 :(得分:0)

您在外部括号中缺少一条消息。改为:

NSAutoreleasePool *pool= [[NSAutoreleasePool alloc] init];