In the end, I am not sure I understand completely why the error occurred, but this is what I did to resolve it, and some other related information. Maybe this will help others that come across this question.
- For each header file in my project
- For each
#include "..."
in the header- If there are no references to the class in the
#include
, remove it. - If there are only pointers to the class defined in the
#include
, then replace it with aclass ...
forward declaration. - If there is a member instance of the class defined in
#include
and it makes sense to use a pointer and allocate the member on the heap, then change the member to a pointer, and replace the#include
with aclass ....
forward declaration.
- If there are no references to the class in the
- For each
- Go through my
Globals.h
and move anything that can be moved out of it to more localized and specific header files.- Specifically, remove an
enum
that was defined isGlobals.h
, and place it in a more localized header file.
- Specifically, remove an
After doing all this I was able to make the error go away. Strangely enough, the enum
in Globals.h
seemed to be a catalyst for the error. Whenever I removed it from Globals.h
, the error would go away. I don't see how this enum
could cause the error, so I think it indirectly led to the error somehow. I still wasn't able to figure out exactly how or why, but it has helped me for this guideline when coding in C++:
Don't put anything in a header file unless it needs to be there. Don't place anything in a
Globals.h
that can be placed in a more localized file. Basically, do all you can to reduce the amount of code that is included through the#include
directives.