So I'm reading that for Zero Initialization will initialize:
Every named variable with static or thread-local storage duration that is not subject to constant initialization, before any other initialization
I am using a Singleton with the traditional private constructor and a static public method in which there is a local static singleton object which the method will be return.
My problem is that the class also has a static vector
which is zero-initialized and it seems to be getting initialized after the singleton, meaning that I cannot interact with it. Is there something that governs this initialization order or is that simply implementation defined?
This is a simplification of what my code looks like:
class Foo {
Foo(){ s_vec.push_back(13); }
public:
static Foo& Get() {
static Foo singleton;
return singleton;
}
int Front() const { return s_vec.front(); }
static vector<int> s_vec;
};
vector<int> Foo::s_vec;
I'm running into this problem because elsewhere in the code I'm initializing a static global variable like this and not getting 13: static const auto element = Foo.Get().Front()