I am having quite the issue with forward declarations. I have a class, SharedContext.h
that has, among other things, a pointer to another class StateMachine.h
. StateMachine also has a pointer to the SharedContext. This would be easy enough if that was all. I have other classes like this already. I would just need to:
#include "StateMachine.h"
in my SharedContext.h
file, and forward declare the SharedContext in the StateMachine.h
file, then #include "SharedContext.h"
in the StateMachine.cpp
file.
This breaks down however, when I need to include more classes into StateMachine
. I have a State_Base.h
, and a State_DIYACMenu.h
and State_DIYACMenu.cpp
. State_Base.h
also has a pointer to SharedContext
, and needs to include it. State_DIYACMenu.h
obviously includes State_Base.h
, and then finally my StateMachine
includes the State_DIYACMenu
. So there is the circular dependency.
I thought I would then be able to solve this by using a forward declaration of SharedContext in State_Base.h
, then using #include "SharedContext.h"
in the State_DIYACMenu.cpp
and StateMachine.cpp
. But I am still getting a "Member access into incomplete type StateMachine" error in the StateMachine class.
Link to the github project: https://github.com/djpeach/DIY-Arcade-Cabinet/tree/master/menu/menu