【发布时间】:2010-07-23 13:00:38
【问题描述】:
我正在尝试通过将父对象作为属性传入来调用对象父对象的方法。 但我不断收到此错误:
“轮子”之前的预期说明符限定符列表
@interface Car : NSObject {
Wheel *w;
}
- (void)doCarStuff;
@end
@implementation Car
- (id)init {
if((self = [super init])) {
//w = [[Wheel alloc] init];
//w.parent = self;
}
return self;
}
- (void)doCarStuff {
NSLog(@"Car stuff");
}
@end
@interface Wheel : NSObject {
Car *parent;
}
@property (nonatomic, assign) Car *parent;
@end
@implementation Wheel
@synthesize parent;
- (id)init {
if((self = [super init])) {
[parent doCarStuff];
}
return self;
}
@end
这可能是因为我必须在 Wheel 之前声明 Car,反之亦然。 我敢打赌解决方案很简单,我看不到它:P
【问题讨论】:
标签: iphone objective-c cocoa-touch oop