• ### Announcements

#### Archived

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

# Make a variabele available to all cpp files

## 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 on other sites
use the "extern" keyword. for example:
  // main.cppint iSomething;..............// text.cppextern int iSomething..............

Ok thank you!!!

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627682
• Total Posts
2978614

• 13
• 12
• 10
• 12
• 22