开发者

"Incompatible types in initialisation" error makes no sense

开发者 https://www.devze.com 2023-01-04 02:47 出处:网络
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 fo

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

精彩评论

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

关注公众号