How to declare a global variable in C++

I know one should not use global variables but I have a need for them. I have read that any variable declared outside a function is a global variable. I have done so, but in another *.cpp file, that variable could not be found. So it was not really global. Isn’t it so that one has to create a header file GlobalVariabels.h and include that file to any other *cpp file that uses it?

Leave a Comment