Re: Assign Reference to another Referance
On 25 Set, 22:40, cpisz <cp...@austin.rr.com> wrote:
I'll give you a compilable example as
soon as I get VS fixed later today.
Good! Please do so!
class Singleton
{
public:
static Singleton & Instance()
{
if( !m_instance )
{
m_instance = new Singleton();
}
return *m_instance;
}
static void DoStuff()
{
int x = 1 + 1;
}
private:
static Singleton * m_instance;
};
Singleton * Singleton::m_instance = 0;
class Foo
{
public:
Foo(){}
~Foo()
{
Singleton::Instance().DoStuff();
}
};
int main()
{
static Foo foo;
return 0; // Undefined behavior after this line, when program
cleanup occurs!
}
static de-initialization fiasco.
Sorry for dropping in, maybe I have not the right grip on the subject
but I want to show what I understand about your program, and take the
chance to learn something new.
If I get it right, this is the sequence:
--- start of execution
- m_instance gets created
- foo gets created
- main returns
- foo starts being destroyed
- a Singleton gets created
- x gets created
- x gets destroyed
- foo finishes its destruction
- m_instance gets destroyed
--- end of execution
Have I got it right? How that relates to the de-initialization fiasco?
Don't take me wrong, those are sincere questions.
Have good time,
Francesco
--
Francesco S. Carta, hobbyist
http://fscode.altervista.org