i’m having some weird compiler errors in objective-c:
iBody.h:18: error: ISO C++ forbids declaration of 'iObject' with no type
iObject.h
#import "iElement.h"
#import "CCSprite.h"
#import "iBody.h"
@interface iObject : iElement
{
iBody *body;
}
-(iObject*)initElement:(CGPoint)pos
withName:(NSString*)name
zIndex:(NSInteger)z
withImage:(NSString*)image;
-(void) addBody: (iBody*) body;
-(iBody*) getBody;
@end
iBody.h
#import "iObject.h"
#import "b2Body.h"
@interface iBody : NSObject
{
CGPoint position;
float angle;
b2Body *body;
iObject *parent;
}
-(iBody*) initElement: (CGPoint) pos
withAngle: (float) angle
withParent: (iObject*) el;
-(void) setBody: (b2Body*)bdy;
-(iObject*) getParent;
@end
can someone please explain why this is happening and how to fix it. The implementation of the classes have .mm extension.
Thanks!
It seems like you’re in an import loop, since the headers of iBody and iObject are linking to one another. Typically in this situation I would consider the iObject to be of higher status and use the following in
iBody.h:Now there is no import loop and only the implementation file of iBody actually links to
iObject.h, and since no headers link toiBody.mmthe issue is solved. Also, remember to rename the implementation files to.mm(Obj-C/C++) when working with Box2D, that gets me now and then 🙂