Jump to content
  • Advertisement
Sign in to follow this  
garyfletcher

problem with globals

This topic is 4829 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 have a variable declared in a header file apps.h: static boost::shared_ptr<aClass> varname; I want it to be visibale through all the project files so I have it static. BUT this is causing problems with my stack. Is there ANY other way I can make this global without it being static?

Share this post


Link to post
Share on other sites
Advertisement
When you make a variable static in global scope, you effectively restrict it from beeing visible outside the file you declared it in. So, the solution to your problem is to define the variable like so:

boost::shared_ptr<aClass> varname;

in your source (.cpp) file and declare it extern like so:

extern boost::shared_ptr<aClass> varname;

in the header file.

[edit]Damn, I'm always too late [headshake][/edit]

Share this post


Link to post
Share on other sites
Sign in to follow this  

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