How to replace scene 1 -> scene 2 then scene 2 -> scene 1 ?

Hi all !

I have trouble with C++ :frowning: .

If i want to replace scene 1 to scene 2 , in scene1.h i need inlude “scene2.h”

and when i replace scene 2 to scene 1 i need include “scene1.h” again .

but in scene1.h still include scene2.h ….

err here :

1>f:2d-x\cocos2d-2.1rc0-x-2.1.3\gofac_cd\proj.win32\gamescene.h(5): error C2011: ‘GameScene’ : ‘class’ type redefinition
1> f:2d-x\cocos2d-2.1rc0-x-2.1.3\gofac_cd\proj.win32\gamescene.h(5) : see declaration of ‘GameScene’
1>f:2d-x\cocos2d-2.1rc0-x-2.1.3\gofac_cd\proj.win32\gvbuttonsprite.h(5): error C2011: ‘GVButtonSprite’ : ‘class’ type redefinition
1> f:2d-x\cocos2d-2.1rc0-x-2.1.3\gofac_cd\proj.win32\gvbuttonsprite.h(5) : see declaration of ‘GVButtonSprite’
1>f:2d-x\cocos2d-2.1rc0-x-2.1.3\gofac_cd\proj.win32\choosebutton.h(6): error C2011: ‘ChooseButton’ : ‘class’ type redefinition
1> f:2d-x\cocos2d-2.1rc0-x-2.1.3\gofac_cd\proj.win32\choosebutton.h(6) : see declaration of ‘ChooseButton’
1>f:2d-x\cocos2d-2.1rc0-x-2.1.3\gofac_cd\proj.win32\gamescene.h(1): fatal error C1014: too many include files : depth = 1024

someone answer me please :frowning: sorry my english not good

does your header files have include guards?

#ifndef SOME_FILE_H
#define SOME_FILE_H


/// Your header file



#endif

Thanks for your help :smiley:

So it worked? right?

yes it’s work perfect :smiley:
thank you again :smiley: .

GVBox Production wrote:

yes it’s work perfect :smiley:
thank you again :smiley: .

the Brandon’s solution is correct. But if you use only the class name for declare a variable, you can define
class Scene1; before your class, and include .h inside cpp. This is a good tech for not recompile all sources when
you change a row in a .h

— classB.h —-

class A;

class B {

private:
A* ptrToA; // ok
A
ptrToAA; // wrong because we don’t include classA.h

};

— classB.cpp —

#include “classA.h”