Archived

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

Seriema

Including globals in .h ONCE

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