We cannot determine the order of the initialization of static objects.
But is this a problem in the following example?
- one static variable is a map (or other container)
- from other static variable we populate that map
the code:
class Factory
{
public:
static bool Register(name, func);
private:
static map<string, func> s_map;
};
// in cpp file
map<string, func> Factory::s_map;
bool Factory::Register(name, func)
{
s_map[name] = func;
}
and in another cpp file
static bool registered = Factory::Register("myType", MyTypeCreate);
When I register more types I don't depend on the order in the container. But what about the first addition to the container? Can I be sure it's initialized "enough" to take the first element?
Or it's another problem of "static initialization order fiasco"?