开发者

"Incompatible types in initialisation" error makes no sense

I have开发者_StackOverflow中文版 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?!?

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


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


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

-(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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜