We cannot determine the initialization order of static objects.
But is this a problem in the following example?
- one static variable is a map (or another container)
- from another static variable we populate this map
the code:
class Factory
{
public:
static bool Register(name, func);
private:
static map<string, func> s_map;
};
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 will not depend on the order in the container. But what about the first add to the container? Can I be sure that he initialized "enough" to take the first element?
Or is this another issue of the "static initialization fiasco order"?
source
share