Exactly. And the error 'unresolved external variable' that you were receiving was because you didn't define the variable anywhere. extern keyword doesn't define a variable i.e. doesn't allocate memory for it but gives compiler a hint that the variable is defined somewhere else and it's safe to use it down in the file.
Originally posted by souldog
Don't use a global variable for this. Add a static member to
your class instead.
You're right, static class member should be used. Is it me, or has there been an influx of "how do you use global variables" messages in the various C++ forums lately?
I'm asking this because usage of global variables should be discouraged. But unfortunately, it seems that others are reading very bad C++ books, reading C programming (not C++) books, or being taught by persons who really aren't good C++ programmers. I have a 100+ module library, and nowhere in there is a global variable that is shared between modules.