S
Stuart MacMartin
I have a problem with static lifetime (order of destruction of statics
within different cpp files). I have a workaround that happens to work
in my case. I'd like to know if this is luck or required to work.
Consider:
class A {
...
static B m_b;
static C& GetC();
};
and in cpp:
C A::m_b;
C& A::GetC()
{
static C c;
return c;
}
and in some other cpp:
static A myA;
The problem I had was with B: A::m_b was destroyed before myA. When I
switched it to be done as a static function with static variable, all
seemed fine. Luck or correct? If luck, how do I ensure myA gets
cleaned up before class A's class variables?
Stuart
within different cpp files). I have a workaround that happens to work
in my case. I'd like to know if this is luck or required to work.
Consider:
class A {
...
static B m_b;
static C& GetC();
};
and in cpp:
C A::m_b;
C& A::GetC()
{
static C c;
return c;
}
and in some other cpp:
static A myA;
The problem I had was with B: A::m_b was destroyed before myA. When I
switched it to be done as a static function with static variable, all
seemed fine. Luck or correct? If luck, how do I ensure myA gets
cleaned up before class A's class variables?
Stuart