typedef enum
{
white,
black,
yellow
}DYcolor;typedef enum
{
woman,
man
}DYsex;
@interface Dog:NSObject
{
@public
DYcolor _color;
int _speed;
DYsex _sex;
float _weight;
}
- (void)eat;
- (void)bar;
- (void)run;
-(BOOL)comparecolor:(Dog *)other;
-(int)comparespeed:(Dog *)other;@end@implementation Dog
-(void)eat
{ _weight+=0.5;
NSLog(@"current weight=%f",_weight);
}
-(void)bar
{
NSLog(@"color=%d,speed=%d,sex=%d,weight=%f",_color,_speed,_sex,_weight);
}
-(void)run
{
_weight-=1;
NSLog(@"current weight=%f,speed=%d",_weight,_speed);
}
-(BOOL)comparecolor:(Dog *)other
{
return _color==other->_color;
}
-(int)comparespeed:(Dog *)other
{
return _speed-other->_speed;
}
@endint main()
{
Dog *p=[Dog new];
p->_color=black;
p->_sex=man;
p->_speed=5;
p->_weight=30;
[p eat];
[p bar];
[p run];
[p comparecolor:white]; [p comparespeed:6]; //Implicit conversion of 'int' to 'Dog *' is disallowed with ARC return 0;
}
求解释
{
white,
black,
yellow
}DYcolor;typedef enum
{
woman,
man
}DYsex;
@interface Dog:NSObject
{
@public
DYcolor _color;
int _speed;
DYsex _sex;
float _weight;
}
- (void)eat;
- (void)bar;
- (void)run;
-(BOOL)comparecolor:(Dog *)other;
-(int)comparespeed:(Dog *)other;@end@implementation Dog
-(void)eat
{ _weight+=0.5;
NSLog(@"current weight=%f",_weight);
}
-(void)bar
{
NSLog(@"color=%d,speed=%d,sex=%d,weight=%f",_color,_speed,_sex,_weight);
}
-(void)run
{
_weight-=1;
NSLog(@"current weight=%f,speed=%d",_weight,_speed);
}
-(BOOL)comparecolor:(Dog *)other
{
return _color==other->_color;
}
-(int)comparespeed:(Dog *)other
{
return _speed-other->_speed;
}
@endint main()
{
Dog *p=[Dog new];
p->_color=black;
p->_sex=man;
p->_speed=5;
p->_weight=30;
[p eat];
[p bar];
[p run];
[p comparecolor:white]; [p comparespeed:6]; //Implicit conversion of 'int' to 'Dog *' is disallowed with ARC return 0;
}
求解释
-(int)comparespeed:(Dog *)other
{
return _speed-other->_speed;
}
这个实例方法 写的传进来的参数是Dog 类型,可是你在main函数里面传的是int 类型,这样肯定会报错吧!我没用Xcode不知道,难道你的编译器不会报错?我觉得应该会报错的吧!