Strange compiler behaviour

Today I experienced a very strange compiler issue. I started the compilation and it outputted that a member object of a class was undefined. After about 4 hours of trying the find the bug I commented and then uncommented said line of code that was undefined. Sure enough the compilation worked just from commenting and uncommenting.

I am using Microsoft visual studio 2012 express. Due to the size of the project, I should know the cause because it may cause more problems further down the line. I feel that it might have something to do with the compiler not having a proper order of compilation for the header files and that I might need something to solidify the way that the header files are processed.


The below code is a fragment of a header file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class CInGameSection: public CBaseGameSection
{
public:
	CInGameSection(bool isInEditor, bool creatingNew, COutput& output, string saveSlot, string regionName, horiVertiVals * widthAndHeight);
	~CInGameSection();
	bool update(CInput & input, CAudio & audio, COutput & output);
	void output(CInput & input, CAudio & audio, COutput & output);

	CInGameManager * getManager();
	
private:
	CInGameManager manager;//VERY VERY UNSTABLE ON COMPILATION, comment and uncomment to compile...
};


Last edited on
I turns out that I am using circular header inclusion which is a nightmare. But this still should't happen.
CInGameSection clearly has to know the CinGameManager, because sizeof(CInGameSection) depends on sizeof(CInGameManager).

Do you mean by circular that the CInGameManager has to know CInGameSection, or are there more in the circle?


You could replace CInGameManager with a CInGameManager* in this header, in which case a predeclaration class CInGameManager; will suffice in this header.
You are totally right! Making CInGameManager a pointer has solved the problem. Thankyou, I can now continue to progress.
Topic archived. No new replies allowed.