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;
}
求解释

解决方案 »

  1.   

    Dog继承NSObject,是OC类型,int是基本数据类型,不能转换
      

  2.   

    我看了几天ios的课程然后看到你的代码,你的
    -(int)comparespeed:(Dog *)other
    {
        return _speed-other->_speed;
    }
    这个实例方法 写的传进来的参数是Dog 类型,可是你在main函数里面传的是int 类型,这样肯定会报错吧!我没用Xcode不知道,难道你的编译器不会报错?我觉得应该会报错的吧!