   Cross-includes issues in C++
  OiOnce again, i'm not quite sure this is the right section for this question, but I figure this probably is rather trivial (not for a newbie like me of course).So, here's the deal, when I cross-include two header files a third one give me a hard time. What I do, basically, is this:First, my classes and what they do:GAME: Keeps track of everything, creates scene-objects and places them in linked lists.SCENE: A superclass, that hold some virtual functions and variables common to all scenes.SCENE_MENU: A menu scene object (doh), instances of this is created in GAME.The class GAME needs to include SCENE (since it will be creating a lot of scenes) but SCENE also needs to include GAME (it wants a parent variable pointing to the game which created it). Using class prototypes,everything works, but when SCENE_MENU wants to include SCENE i get a strange error message: "error C2504: 'SCENE' : base class undefined"It points on SCENE_MENU's class definition which looks like this:class SCENE_MENU:public SCENE I don't know what's wrong, I tried using class prototypes in SCENE_MENU with no effect. Does anyone have an idea what could be wrong?I'd be very thankful for any suggestions!/Mekanikles(I could post some code as well, but I dont know if there's any "<,/,["-tags for it, sorry)   
  game.h does not need to include the other 2 files, unless you are specifically writing functions in game.h that are calling funcs in scene and scene manager. If you are, then move that stuff into game.cpp where it should be. game.cpp needs to include the other files though.// game.hclass SCENE;class SCENE_MENU;class GAME { // definition};// scene.h#include "game.h"class SCENE { // definition};// scene_menu.h#include "scene.h"class SCENE_MENU : public SCENE { // definition};;Quote:Original post by MekaniklesOiOnce again, i'm not quite sure this is the right section for this question, but I figure this probably is rather trivial (not for a newbie like me of course).So, here's the deal, when I cross-include two header files a third one give me a hard time. What I do, basically, is this:First, my classes and what they do:GAME: Keeps track of everything, creates scene-objects and places them in linked lists.SCENE: A superclass, that hold some virtual functions and variables common to all scenes.SCENE_MENU: A menu scene object (doh), instances of this is created in GAME.The class GAME needs to include SCENE (since it will be creating a lot of scenes) but SCENE also needs to include GAME (it wants a parent variable pointing to the game which created it). Using class prototypes,everything works, but when SCENE_MENU wants to include SCENE i get a strange error message: "error C2504: 'SCENE' : base class undefined"It points on SCENE_MENU's class definition which looks like this:class SCENE_MENU:public SCENE I don't know what's wrong, I tried using class prototypes in SCENE_MENU with no effect. Does anyone have an idea what could be wrong?I'd be very thankful for any suggestions!/Mekanikles(I could post some code as well, but I dont know if there's any "<,/,["-tags for it, sorry)Your problem is called a circular dependency. While you can find a syntax-wise, technical solution to your problem, you should consider changing your design, because circular dependencies are often visible signs of incorrect software design. To me, without seeing your code, I believe that your Game class acts like a god class - and that's why your scene class needs to know about it. 1) cut down your game class into smaller class - and if you want it, aggregate these classes into a composed Game class. 2) now, your scene class only need to know some specific sub objects of Game - and these objects don't need to know about the scene class. Whenever you face a circular dependency, you should ask yourself why you need it and how you could remove it. HTH,   ;  Thanks alot!Didn't quite understand what you meant first so I made some research and you were right, it works fine now. I've learned alot :)Thanks again /Mekanikles   ;  Oh, Emmanuel made a post while I was busy thanking Rob :) didn't see that, srryI know Mr Mackey says circular dependencies are baad, but I don't see an obvious way around them right now.The reason im doing this is that my GAME class indeed acts a "god", some projects i've been looking at choose to call it "world" or something like it. Now this world basically has a linked list of SCENEs that works exaclty like a stack (it doesn't have to be a linked list) where the top stack-scene is the current scene running. Now, the way I've built the code, a stack-object cannot delete itself (that would result in numerous memory errors) so GAME need to check the first element in the list every frame and delete it if it isn't active, thus GAME needs to include SCENE. The reason for SCENE to include GAME is really the PLAYER class (the plot thickens...). GAME creates a couple of PLAYER instanses which then is accessed from the SCENEs through a parent pointer (every SCENE needs to be able to reference the same player object).Is there a common way to easily solve the player-access issue? (a hideous global perhaps?)I hope I clarified a thing or two, thanks for taking an interest anyway ;)/Mekanikles   ;Quote:Original post by MekaniklesIs there a common way to easily solve the player-access issue? (a hideous global perhaps?)I hope I clarified a thing or two, thanks for taking an interest anyway ;)/MekaniklesSimplest thing that I see:Game needs SceneScene needs PlayerGame needs PlayerThus the player is created by the Game object, not by the scene. It is only used by the scenes.If you feel that the player should really be created by the Scene, consider using a particular method is Scene to do the job, and return the resulting pointer to Game. HTH,   ;  Ok, I will consider what you said, thank you./Mekanikles   