C
cppaddict
I would like to know the best way to initialize complex static member
variables. In addition, I want to avoid creating an Init() method
that is called by the ctor, since there's no need to wait for that
call in my application. My current attempt is OK, but it creates an
extra member variable that is extraneous:
<code>
class A {
private:
static std::vector<int> _v;
static bool init();
static bool isInit;
public:
A() : _a(1) {}
};
// This would go in the implementation file
std::vector<int> A::_v;
bool A::init() {
_v.push_back(1);
_v.push_back(2);
return true;
}
bool A::isInit = A::init();
</code>
Is there a better way to do this?
thanks for any thoughts,
cpp
variables. In addition, I want to avoid creating an Init() method
that is called by the ctor, since there's no need to wait for that
call in my application. My current attempt is OK, but it creates an
extra member variable that is extraneous:
<code>
class A {
private:
static std::vector<int> _v;
static bool init();
static bool isInit;
public:
A() : _a(1) {}
};
// This would go in the implementation file
std::vector<int> A::_v;
bool A::init() {
_v.push_back(1);
_v.push_back(2);
return true;
}
bool A::isInit = A::init();
</code>
Is there a better way to do this?
thanks for any thoughts,
cpp