#import<Foundation/Foundation.h>
@interface Pig : NSObject
{
@public
float wheight;
}
-(void)eat;
@end
@implementation Pig
-(void)eat
{
NSLog(@"本猪吃了一顿,现在的体重是:%.1f斤",wheight);
wheight++;
}
@end
int main()
{
Pig* piggy=[Pig new];
piggy->wheight=90;
for (int i=0; i<10; i++)
{
[piggy eat];
}
return 0;
} |
|