views:

39

answers:

1

I'm trying to call methods on the parent of my object by passing the parent in as property. But i keep getting this error:

expected specifier-qualifier-list before 'Wheel'

@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

It is probably because i have to declare the Car before the Wheel and vise versa. I bet the solution is so simple i can't see it :P

+2  A: 

Forward-declare Wheel before Car.

@class Wheel;

@interface Car : ...

(BTW, in Wheel's -init method, parent is not initialized (thus always nil), therefore calling [parent doCarStuff] there is useless.)

KennyTM
Now i get this error, wich is even more confusing.ld: duplicate symbol .objc_class_name_Wheel in ..collect2: ld returned 1 exit statusCommand /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1
Sveinn Fannar
nevermind, i got this.Thank you so much :)
Sveinn Fannar