Can I safely store things in a vector in constructors of non-pod static data member constructors? Example:
class Foo
{
public:
static Foo& instance()
{
static Foo inst;
return inst;
}
void store(int x) { numbers.push_back(x); }
private:
Foo() {}
std::vector<int> numbers;
};
class Bar
{
public:
Bar() { Foo::instance().store(5); }
};
class Thing
{
public:
static Bar bar;
};
// in thing.cpp:
Bar Thing::bar;
Is the above code correct and produces defined behavior?
Note: The question is not about static locals, but about std::vector
depending on any static initialization that might not happen until the bar constructor.