#import <Foundation/Foundation.h>
@interface Person : NSObject
{
@public
int age;
double height;
}
- (void)print;
@end
@implementation Person
- (void)print
{
NSLog(@"年龄=%d,身高=%f", age, height);
}
@end
int main()
{
[Person new]->age = 10;
[Person new]->height = 1.8;
[[Person new] print];
return 0;
}
执行一次Person new方法就创建一个对象,内存中就开辟一个区域,故输出为0.000000 |
|