-3

嗨,我正在尝试学习 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;
}


}
4

1 回答 1

0

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

NSAutoreleasePool *pool= [[NSAutoreleasePool alloc] init];
于 2013-08-17T20:31:48.223 回答