Jump to content
  • Advertisement
Sign in to follow this  
Endar

Header file problems

This topic is 4865 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!