B
better_cs_now
Hello all,
Please consider the following code:
class Bar;
class Foo {
Bar *m_pBar;
public:
Foo(Bar *pBar): m_pBar(pBar) {}
};
class Bar {
Foo m_Foo;
public:
Bar(): m_Foo(this) {}
};
It would certainly be wrong for Foo::Foo() to dereference pBar since
the Bar object is still being constructed and therefore does not
exist. However, is it wrong to even cache off the pointer for later
use as shown?
Thanks,
Dave
Please consider the following code:
class Bar;
class Foo {
Bar *m_pBar;
public:
Foo(Bar *pBar): m_pBar(pBar) {}
};
class Bar {
Foo m_Foo;
public:
Bar(): m_Foo(this) {}
};
It would certainly be wrong for Foo::Foo() to dereference pBar since
the Bar object is still being constructed and therefore does not
exist. However, is it wrong to even cache off the pointer for later
use as shown?
Thanks,
Dave