Static members are basically globals, and are initialized exactly once when the program starts up. The only issue that could happen is if you have one static member's initialization depend on the state of another static member. IE:
1 2 3
|
// in class1.cpp
int class1::astaticvar = 5;
|
1 2 3
|
// in class2.cpp
int class2::anotherstatic = class1::astaticvar + 2;
|
This is known as the "static initialization order fiasco". Since both statics reside in different compilation units (different source files), there is no way to know which will be initialized first. So class2's variable is trying to read class1's variable... but it might not have been initialized yet.
EDIT:
What would be the issue/problem in case static data memebr initilization will be done within an function, the function has been called mutliple times during programm execution? |
Errm... well I might have misunderstood your question, because static
members are initialized once globally, they are not initialized in functions.
If you have a static variable that is not a class member, that works a little differently:
1 2 3 4
|
void afunction()
{
static int foo = 15; // <- static local var (not a member var)
}
|
'foo' will be initialized with 15 the very first time afunction is called. Every time afunction is called after that, it will retain its previous value (it will not be assigned to 15 each time).
The only way this could go wrong is if you are multithreading, and two threads call afunction at the same time without some kind of mutex to guard it.
But maybe this is not what you mean? Can you post an example of what you're doing so I can understand more clearly?