- #import <Foundation/Foundation.h>
- @interface Person : NSObject
- {
- @public
- char *name;
- int age;
- double height;
- }
- - (void)run;
- @end
- @implementation Person
- - (void)run
- {
- NSLog(@"%s,今年%d岁,身高%f,跑起来了",name,age,height);
- }
- @end
- int main()
- {
- Person *p =[Person new];
- p->name="张三";
- p->age=23;
- p->height=1.80;
- [p run];
- return 0;
- }
复制代码
macdeMacBook-Air:tanchao mac$ cc 10-类的练习.m -framework Foundation macdeMacBook-Air:tanchao mac$ ./a.out 2015-03-09 23:58:27.236 a.out[576:25981] ,今年23岁,身高1.800000,跑起来了 macdeMacBook-Air:tanchao mac$
|