“初始化中不兼容的类型”错误没有意义

时间:2022-09-10 02:14:29

I have been a Java programmer for years but only iPhone/Obj-c for a few months. Every time I think I'm comfortable with the language something weird happens. Why does the following generate a "Incompatible types in initialisation" compile error? It seems so straight forward. 'double' is a primitive right?!?

多年来我一直是Java程序员,但只有iPhone / Obj-c几个月。每当我觉得我对语言感到满意时,就会发生奇怪的事情。为什么以下生成“初始化中的不兼容类型”编译错误?看起来很直接。 'double'是一个原始的权利?!?

-(void) testCalling{
   double myDoub = [self functionReturningDouble:3.0];
}


-(double) functionReturningDouble:(double) input{
   return 1.0;
}

1 个解决方案

#1


0  

Try to swap the method declarations. It may be a scope problem as Georg notices:

尝试交换方法声明。这可能是范围问题,因为Georg注意到:

-(double) functionReturningDouble:(double) input{
    return 1.0;
}

-(void) testCalling{
    double myDoub = [self functionReturningDouble:3.0];
}

In Objective-C (and this is valid for C), a method does "exists" only if it has been defined or declared before.

在Objective-C中(这对C有效),只有在之前定义或声明了方法之后,方法才会“存在”。

#1


0  

Try to swap the method declarations. It may be a scope problem as Georg notices:

尝试交换方法声明。这可能是范围问题,因为Georg注意到:

-(double) functionReturningDouble:(double) input{
    return 1.0;
}

-(void) testCalling{
    double myDoub = [self functionReturningDouble:3.0];
}

In Objective-C (and this is valid for C), a method does "exists" only if it has been defined or declared before.

在Objective-C中(这对C有效),只有在之前定义或声明了方法之后,方法才会“存在”。