I started using C++ for object oriented programming and I've come across static member variables.
In my particular case, I have the following in my header file (Class.hpp):
private:
const static string DEFAULT_PATH;
static string path;
Not that really matters, but is as valid as any example.
So, to do the proper initialisations I had to do some research and find out that this can't be done in the class body and has to be done in the source (Class.cpp) file. In my source file, I added:
const string Class::DEFAULT_PATH = "./";
string Class::path = DEFAULT_PATH;
I found this to be counter-intuitive, but tried to deal with it. Then I wondered:
When exactly did the compiler call this initialization code? How can I assume when will this fields have a value? I don't really understand what's happening there and I'd like to know.
And what's most intriguing for me: which symbols can I see whithin Class.cpp when including class.hpp? And why those declarations have be outside the class body and in another file?