I am working on an iPhone game using the cocos2d framework, and recently encountered a problem I can't seem to solve. After adding a new class to my project and doing some work in it, I tried to compile my code and several of the classes I hadn't even touched broke. It seems like those classes just forgot how import external classes. I am getting the error up there in several of my classes, but here is one example:
#import "cocos2d.h"
#import "XZombie.h"
#import "WayPoint.h"
#import "XBuilding.h"
//@class XBuilding;
@interface Hoarde : CCNode
{
float _spawnRate;
int _totalXombies;
NSMutableArray *_path;
XBuilding *_target;
NSMutableArray *_zombies;
bool _zombiesReset;
}
@property (nonatomic) float spawnRate;
@property (nonatomic) int totalXombies;
@property (nonatomic, retain) NSMutableArray *path;
@property (nonatomic, retain) XBuilding *target;
@property (nonatomic, retain) NSMutableArray *zombies;
@property (nonatomic, assign) bool zombiesReset;
- (id) initWithZombieCount:(int)totalXombies Target:(XBuilding *) target SpawnRate:(float)spawnrate;
- (void) resetZombies;
@end
I get the error on the line that reads XBuilding *_target;
If I uncomment the @class XBuilding;
, the error goes away, so while that doesn't really solve my problem, it gives me a tool to work around it.
If I do the @class
trick for all the files I am having a problem with, I can work around that. The thing is, I get a new - but similar - error besides the specifier-qualifier-list one. Some lines of code give me Expected a ')' before *token
or Expected a ';' before *token
. Those lines usually gave me the previous error as well, so the @class trick worked as well, but I haven't the slightest idea why this stuff is doing what it's doing. I read somewhere (the cocos2d forums, I think) that renaming the .m files to .mm might do the trick, but it didn't for me.
So, while I can continue working on my project, I would really like to know how on Earth to avoid stuff like that in the future...