Header file problems

Started by
3 comments, last by Spudder 18 years, 9 months ago
The possible problem is that I have the bad habit of writing all my class code inside the class definition, inside the header file. I know, I know, its just that it gets really tedious going from file to file to file to file, etc, etc when you have 10 or so open, looking for the right function to finish writing.

class COGLWindowManager;	// forward declaration

class COGLWindow{
	// code code code
	COGLWindowManager::Get().setFocus(this);
	// code code code

};

class COGLWindowManager{

};


At the only line of actual code, I'm getting a "use of undefined type 'COGLWindowManager'" error, and the next two error deal with Get() and setFocus being unusuable, due to the first one. So, is the problem that I have all my code in a single header file?
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
Advertisement
After a forward declaration you can't use any member functions, for this you need the whole class interface, and that's the point where you need to get the code out of your header file...
You can repair something for this specific example, but there are many more where you can't. You should not define any functions within the body of a class; not even trivial constructors. The time you spend seperating them will save you hours of repeated dependency problems such as this.
For that little problem, it just took me 20 minutes to move 3 functions from the COGLWindowManager class to a source file in the project and have everything work as before.

I think I might start seperating from now on.
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
If your forward declaring a class then all you can do is store a pointer to that class or a reference. In order to call any methods of that class or create an instance the compiler needs more details which is only available by including the class's header file.

This topic is closed to new replies.

Advertisement