Organizational System Giving Errors

I'm making a game with the following class structure:

GameControl - The class that actually runs the game, with a while(!closed) // run the game loop.

State - A class that handles the state of the game, for example if the game is rendering the scene it would be in one state, and if it is rendering the menu, it would be in another.

ComponentManager - A class that manages all of the components of what is being done, for instance, the Scene class would contain a bunch of components handling the drawing of each tree, physics, the camera, etc. The manager will put them all together.

Component - A component of whatever is being done. A tree (and its rendering code) would be an example of a component of the scene. The camera would be another. The component does not necessarily have to be drawn, it could be handling something like physics (and would throw physics events to other components that need to move in a certain way).

The GameControl class has its loop, which would call the update function on the current State (there are classes that inherit State and override the update function of State).

In the update function of the base class "State", it would take all of the active ComponentManagers and update them. There are classes that inherit the base class ComponentManager and override its update function.

Each ComponentManager would update each of the Components that it owns.

This is the organizational structure that I came up with to make the game scalable and changeable . If, for instance, I wanted to add multiplayer at some point, I would add a class that inherits the State that controls the gameplay called "MultiplayerGameState". This would just add a new ComponentManager that inherits the ComponentManager that controls the player and all of the living things that are moving around. Then, the MultiplayerGameState class would recieve the multiplayer messages coming in and add other player Components for the other players.

My code is giving me various errors like "Forward definition of class State" and "Invalid use of incomplete type State". Unless I made some stupid error that I didn't catch, these are being caused by me including the classes in ways that some of the classes do not see the full definitions of the classes they need to see (because of the preprocessor directives preventing classes from being included multiple times.

Code: (Not implemented exactly as shown above, but I think the main difference is that the main class is not in GameControl, it's in OgreFramework.cpp)

The base classes:

The project:

Assuming I didn't make a stupid mistake, I understand why this is happening. My question is: is there a better way to implement my organizational system so that these errors don't occur?

I may have left out some important information. If you need more information, please don't hesitate to ask. Thank you for taking the time to read this long post, I really appreciate it!
Last edited on
because of the preprocessor directives preventing classes from being included multiple times
No, that's not the problem. Yes, the preprocessor prevents due to the header guards that the content of a file appears more than once, but once is enough.

The problem is that you don't include everything necessary. For instance State.h:
You need to #include <CommandChain.h>

Forward declarations are possible only when you're using nothing but a reference/pointer to that object. Inheritance is of course not possible in that case.

I suggest to use forward declarations as sparse as possible. Otherwise you will face this kind of compiler error frequently
Last edited on
Topic archived. No new replies allowed.