【发布时间】:2014-10-24 13:31:56
【问题描述】:
我在一个相当简单的脚本中调用方法时遇到问题。
由于某种原因,当我运行程序时,我在控制台中得到的只是返回 0。
我能做些什么来解决它?这是我的脚本:
#import <Foundation/Foundation.h>
@interface person:NSObject {
int weight;
int height;
int age;
}
- (void)printtoscreen;
- (void)setweight:(int)w;
- (void)setheight:(int)h;
- (void)setage:(int)a;
@end
@implementation person
-(void) printtoscreen {
NSLog(@"I am %i years old, I weigh %i pounds, and I am %i feet tall", age, weight, height);
}
- (void)setweight:(int)w {
w=weight;
}
- (void)setheight:(int)h {
h=height;
}
- (void)setage:(int)a {
a=age;
}
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
person *bob;
[bob setweight:150];
[bob setheight:5];
[bob setage:25];
[bob printtoscreen];
}
return 0;
}
【问题讨论】:
标签: objective-c variables object methods console