我刚刚在Objective C中开始了一系列教程,作为我学习的第一个严肃的编程语言(我有一个非常基本和零散的Android知识)。我正在关注一系列教程视频,并且遇到了错误的代码。本教程的作者完美地使用了相同的代码。我是Objective C的新手,所以我无法弄清楚我的代码有什么问题。这是:
#import <Foundation/Foundation.h>
//-----interface-----
@interface Person: NSObject{
int age;
int weight;
}
-{void} print;
-{void} setAge: {int} a;
-{void} setWeight: {int} w;
@end
//-------implementation-------
@implementation Person
-{void} print{
NSLog(@"I am %i years old and weigh %i pounds", age, weight);
}
-{void} setAge: {int} a{
age=a;
}
-{void} setWeight: {int} w{
weight=w;
}
@end
int main{int argc, char *argV[]}{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc]init];
Person *amrit;
amrit = [Person alloc];
amrit = [amrit init];
[amrit setAge: 16];
[amrit setWeight: 125];
[amrit print];
[amrit release];
[pool drain];
return 0;
}
答案 0 :(得分:1)
-{void} print;
-{void} setAge: {int} a;
-{void} setWeight: {int} w;
返回类型和参数类型应该包含在()
中,而不是{}
中。在进行实施时也一样。