我使用tutorialspoint.com编译目标c代码
@interface Foo{
@public
NSInteger x;
}
-(int) apple;
-(void)setAge:(NSInteger)number;
@end
@implementation Foo
-(int)apple{return 5;}
-(void)setAge:(NSInteger)number{
self->x=number+1;
NSLog(@"%d",self->x);
}
@end
int main (int argc, const char * argv[]){
NSAutoreleasePool *myPool = [[NSAutoreleasePool alloc] init];
Foo *p = [[Foo alloc] init];NSInteger nine = 9;
[p setAge:nine];
[myPool drain];
return 0;
}
,当我尝试编译时,我收到此编译错误:
main.m:41:3: warning: (Messages without a matching method signature
main.m:41:3: warning: will be assumed to return 'id' and accept
main.m:41:3: warning: '...' as arguments.)
答案 0 :(得分:2)
您的班级Foo
没有基类(即NSObject
)。因此,此类不知道+alloc
和-init
。
@interface Foo : NSObject {
…