I would not generally advise to use singleton classes is good style, but here's what I would do:
MySingleton.hpp:
class MySingleton {
public:
static MySingleton& instance() {
static MySingleton theInstance;
return theInstance;
}
std::vector<int>& levels() { return levels_; }
private:
MySingleton() {
}
std::vector<int> levels_;
};
To use the above elsewhere:
#include "MySingleton.hpp"
// ...
MySingleton::instance().levels().resize(10); // Creates 10 ints initialized to 0
To shorten the access you could even wrap the whole thing in its own namespace and provide free functions there:
namespace MySpace {
class MySingleton {
// Blah, blah
};
std::vector& levels() {
return MySingleton::instance().levels();
}
}
and use it
MySpace::levels().resize(10);