Archived

This topic is now archived and is closed to further replies.

Multiple definitions

This topic is 4945 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 am fairly new to c++ programming, coming from delphi and another obscure language. My problem is that I have a number of and files which implement classes. Just a simple example: class ikke { protected: memberlist (); }; ikke::memberlist () { } Nothing fancy there. These classes implement graphics, resource managing and such (or so they will in future). As can be understood, almost everything needs a couple of these objects. So I made a single where I defined a number of pointers to these core classes and the header I include everywhere I need them. However, linking results into multiple definitions and I want to avoid this. So, I included the familiar #ifndef __gameobjs and the #define part off course. But the problem persists. Am I missing something? This is my gmobj.h: #ifndef __GAMEDEFS #if ( __GAMEDEFS == 1 ) #error "here again." #include "windowmanager.h" #include "gfxcore.h" #include "logger.h" #define __GAMEDEFS 1 WindowManager *windowmanager; // A handle to the game window manager gfxcore *screen; // A handle to the game graphics core logger *logbook; // A handle to the logbook #endif

Share this post


Link to post
Share on other sites
Global variables declared in headers should have the extern storage class specifier. Basically change

WindowManager *windowmanager;

to

extern WindowManager *windowmanager;

And then declare storage in one source file by putting

WindowManager *windowmanager;

at namespace scope.

For more details see this article.

Share this post


Link to post
Share on other sites