Saturn
Saturn

Reputation: 18149

Unknown type name

My .h file:

#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "GameData.h"
#import "PROBattleScene.h"

@interface PROBattleAI : NSObject {
    BattleType type;
    PROBattleScene *scene;
}

-(id)initWithType:(BattleType)_type andBattleInformation:(NSMutableDictionary*)_information andScene:(PROBattleScene*)_scene;
-(void)dealloc;
@end

But on the line PROBattleScene *scene; I get the unknown type name error from Xcode.

I tried the answer here: xcode unknown type name but I am already doing that (and doesn't work).

Why is that happening? I am already importing my PROBattleScene.h file, why isn't it being recognized?

EDIT: And the contents of PROBattleScene.h as requested:

#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "GameData.h"
#import "SimpleAudioEngine.h"

#import "PROBattleBackground.h"
#import "PROBattleAI.h"

@interface PROBattleScene : CCLayer {
    NSMutableDictionary *battleInformation;
    NSMutableArray *localPlayerPartyData;

    PROBattleBackground *background;

    CCNode *base;

    PROBattleAI *enemyAI;
}
+(CCScene*)scene;
-(id)init;
-(void)loadBattleInformation;
-(void)loadBGM;
-(void)loadBackground;
-(void)loadBase;
-(void)loadEnemyAI;
-(void)beginBattle;

@end

Upvotes: 2

Views: 9389

Answers (1)

borrrden
borrrden

Reputation: 33421

You have a circular dependency. PROBattleAI imports PROBattleScene which imports PROBattleAI which imports PROBattleScene < zomg infinite loop >

Use @class PROBattleWhatever in your headers as much as possible. Only import headers for protocol definitions or superclasses.

EDIT Ok, the above wording was totally bad...and misleading. Here is what (I believe) happens in detail. Your PROBattleAI imports PROBattleScene, which then imports PROBattleAI, which then imports PROBattleScene for a second time (all before it gets to any of the code in either file). The import will ignore PROBattleScene this time because it has already been imported and you will get the undefined type error since the file was skipped.

Upvotes: 7

Related Questions