Sign in to follow this  

Headache: Inheritance and Redefinition

This topic is 2635 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
{
protected:
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;

public:
DLogin (LOGFONT Font, LPDIRECT3DDEVICE9 Device);
~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

This topic is 2635 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this