Jump to content
  • Advertisement

Archived

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

jaapjan

Multiple definitions

This topic is 5198 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
Advertisement
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

  • 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!