Jump to content
  • Advertisement

Archived

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

Seriema

Including globals in .h ONCE

This topic is 6043 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''m trying to code a little DirectX, but this isn''t that a specific question. But my problem is this. I have global variabels. And I''m using C++ with classes, some class functions use these global variables. For now I have 2 classes (Sprite and DirectX setup, both in separate .h and .cpp files. I''m having HUGE problems declaring these simple global variables/constants. If I try in main.cpp they won''t be declared when it enters the #include''s at the top. So I tried making a globals.h and put all globals there. And I did #ifndef - #define - #endif in it too. And then included globals.h in the other .h''s. Now I get a million linker errors saying that they''re already defined! What is the simplest/best way to declare globals that are accesable EVERYWHERE (all .h, .cpp, .whatever)? thanx... }+TITANIUM+{

Share this post


Link to post
Share on other sites
Advertisement
In your globals.h put ''extern'' in front of all declarations, that tells the compiler that these vars are defined somewhere else in the program and that it is just fine to use them.
Then in some .cpp file put the actual declarations without ''extern''.

Share this post


Link to post
Share on other sites
oh yeah! Now I remember!! I''ve never actually used it, just heard of it like 1 year ago in C-programming class at school *lol*

THANX!

}+TITANIUM+{

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!