ank wrote:
What do you mean "not initialise in the constructor"?
I really don't understand that.
Constructor is responsible for that task, isn't it?
Not in the case of static member variables. The class constructor is
not called before or at the time that the static variable has to
contain a value.
Because you have to give the static variable a value before you have
access to the real values you want to store in it you need to feed the
variable dummy data.
Then in the constructor of the class you assign real values, but to
mimic static initialisation you need to add in a guard so that this
assignment happens only once.
Anyway, my initial guess is that template static data member is either
initialized before the first use by any module or initialized in some
module
A static member of a template class is initialised at the same time any
static member of a non template class is initialised. You have a
guarantee it exists when
template<typename T>
VarType ClassName<T>::VarName = Value;
in the header file is processed.
(and that may be too late for using it by other external static
object).
Existence does not equal accessibility. Unless you have declared the
static variable in the public section of the class, this external
object cannot access your static variable until an object of the class
containing the static variable exists. And even then only through the
appropiate functions of the class.
If you are stuck with static initialisation dependency (That is static
object A has to exist before static object B) I again refer you to
'Thinking in C++' vol 1, chapter 10. That chapter also has strategies
on how to ensure proper initialisation.