- #import <Foundation/Foundation.h>
- typedef enum{
- SexMan,
- SexWoman,
- SexUnkown
- } Sex;
- typedef struct{
- int year;
- int month;
- int day;
- } Date;
- @interface Dog : NSObject
- {
- @public
- Sex SexMan;
- Date _birthday;
- int _weight;
-
- }
- - (void)run;
- - (void)eat;
- @end
- @implementation Dog
- - (void)run
- {
- _weight = _weight + 1;
- NSLog(@"狗跑完这次后的体重是%d",_weight);
- }
- - (void)eat
- {
- _weight = _weight - 1;
- NSLog(@"狗跑完这次后的体重是%d",_weight);
- }
- @end
- int main ()
- {
- Dog *d = [Dog new];
-
- d -> _weight = 19;
- d -> _birthday.year = 2010;
- d -> _birthday.month = 11;
-
- [d run];
- [d eat];
- NSLog(@"体重是%d,出生是%d-%d-%d的狗狗",_weight,_birthday.year,_birthday.month);
-
- return 0;
- }
复制代码
我没有截图软件,就给大家说一下,在最后输出的时候_weight使用了定义不明确的变量,报错,什么原因? |