I have set up a simple dummy program consisting of a main.cpp file, a global.h file that declares some global variables, and then A.h and A.cpp files which declare and define a function that manipulates those variables. All of these files are guarded, yet I am receving "multiple declaration" errors when I try to compile. Here is the code:
That way, if you include it more than once (like you do in main.cpp and A.h) you define them twice. Using the extern modifier, you are declaring them and telling the compiler they are to be defined somewhere. Since you pass only once by the source file where you define them, no multiple definitions.