函数未声明错误



你能指出这个错误吗?为什么编译器认为我的函数是未声明的?谢谢。rob

In .h file

-(int) getW:(int)xPosition;

In .m file

-(int) getW:(int)xPosition {
    return (xPosition-58)/48; 
}

在另一个过程中,调用函数:

whichTile=[getW: xPosition] ;   <----ERROR getW undeclared (first use in this function)

(xPosition和thetile已被声明为整数,并在过程的前面使用)。我也尝试了(NSInteger)(以及其他一百万个排列!)谢谢你的帮助。- rob

您声明了一个实例方法,并且在没有指定实例的情况下调用它。

例如:

whichTile = [self getW:xPosition];
-or-
whichTile = [anObject getW:xPosition];

与其他语言不同,self在消息传递时不是隐式的。

最新更新