Jump to content
  • Advertisement

Archived

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

Subotron

Make a variabele available to all cpp files

This topic is 6011 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

ATM I have a file named main.cpp, which includes the header main.h I want to divide main.cpp in different parts now, so I made different cpp files which all store a few functions. 1 for text, 1 for initializing everything, etc. the problem is, I need a variabele in text.cpp now which I made in main.h, which is included in main.cpp I want the variabele to be available in the other cpp file too. How do I do this? It would be even better if there was a way to include all the variabeles in all the files if that''s possible... I tried including the main.h file in the other documents, but this doesn''t work because it tries to re-make the variabeles... Or am I doing something wrong?

Share this post


Link to post
Share on other sites
Advertisement
use the "extern" keyword. for example:
  
// main.cpp

int iSomething;
...
.....
......

// text.cpp

extern int iSomething
...
.....
......

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!