我是目标 c 的新手,我想通过制作一个简单的程序来练习。由于某种原因,方法 print 将无法运行。有任何想法吗?
#import <Foundation/Foundation.h>
@interface person: NSObject
{
//----Variables----
int age;
}
//----Methods----
-(void) print;
-(void)setAge: (int) a;
@end
@implementation person
-(void) print{
NSLog(@"You are %i years old!", age);
}
-(void) setAge: (int) a{
age=a;
}
@end
int main(int argc, char *argv[]){
@autoreleasepool{
person *alex; alex = [person alloc];
[alex setAge:12];
[alex print];
return 0;
}
}