Jump to content
  • Advertisement
Sign in to follow this  

Headache: Inheritance and Redefinition

This topic is 2918 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

I've been writing my own engine on top of DirectX for a while now, and I'm enjoying the process quite a bit. Unfortunately, I've run into a bit of a snag with my GUI code.

All of the UI components, such a windows and buttons, are derived from a class called UIBaseControl. They're all located in UIBase.h and .cpp.

I was planning on writing each dialog in its own file to avoid clutter. For example, I wrote a separate class for a login window called DLogin (The buttons are commented out because I'm still working on them):

#include "..\\include\\Headers.h"
#include "..\\include\\UIBase.h"
#include "..\\include\\NetworkHandler.h" //For logins

class DLogin
UIWindow* m_Window;

//UITitleBar* m_TitleBar;
UILabel* m_LTitle;
UILabel* m_LServerDetails;
UILabel* m_LServer;
UILabel* m_LServerStatus;
UILabel* m_LCredentials;
UILabel* m_LHandle;
UILabel* m_LPassword;

/*CreateAccountButton* m_BCreate;
LoginButton* m_BLogin;
CancelButton* m_BCancel;*/

UILabel* m_ServerStatusOut;

UITextBox* m_TBServer;
UITextBox* m_TBHandle;
UITextBox* m_TBPassword;

~DLogin ();

void OnSubmit ();

Now, this class works great on its own. The window renders fine, and (when I don't have them commented out) the buttons send the login information to the server.

However, I also wrote another class called DConnect, which is meant to be displayed before the login window. This class also include UIBase.h.

Both of these dialog classes are being #include'd in UIHandler. When only one is included, the engine compiles and runs fine. The moment I include a second dialog into the UIHandler and try to compile I get spammed by error C2011, one for each class in UIBase.h.

Each error informs me that the class is being redefined. For example:
error C2011: 'UIWindow' : 'class' type redefinition

If anyone has any insight on what I've done wrong, I would appreciate the help.

Share this post

Link to post
Share on other sites
Read this.

Having "master" header files such as "Headers.h" that include your own headers can easily cause circular includes, which include guards cannot protect against. Instead, try to reduce the number of #include directives by using forward declarations and breaking unnecessary dependencies.

It isn't so bad to group all your external includes in such a file (as external ones will not try to #include your own headers hopefully). If you do this, you can make this a precompiled header and possibly speed up compilation time.

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!