This is known as the static initialisation order fiasco, and stems from initialisation order of static variables between compilation units being undefined. Putting the static at class scope as you have done won’t help because it doesn’t impose any further constraints on initialisation order. What you need to do is place the static inside a function (or method) as @jules suggested, therefore forcing the static to be initialised when the function is first called. This is sometimes called lazy initialisation.
So you could write:
class SomeClass
{
const std::vector<var>& getVars()
{
static const std::vector<var> m_vars;
return m_vars;
}
}
Then access the static later with:
const auto& vars = SomeClass().getVars() // m_vars is initialised when getVars() is first called
Further explanation can be found here
