Archived

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

Subotron

Make a variabele available to all cpp files

Recommended Posts

Subotron    182
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
123cs    122
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