开始目标C代码错误?怎么了?

时间:2011-10-27 03:21:19

标签: objective-c xcode error-handling

我刚刚在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;


}

1 个答案:

答案 0 :(得分:1)

-{void} print;
-{void} setAge: {int} a;
-{void} setWeight: {int} w;

返回类型和参数类型应该包含在()中,而不是{}中。在进行实施时也一样。