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

## 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 loginsclass 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 on other sites
See if this helps you:

http://en.wikipedia.org/wiki/Include_guard

##### Share on other sites

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.