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