I have the following C++-class:
// Header-File
class A
{
public:
A();
private:
B m_B;
C m_C;
};
// cpp-File
A::A()
: m_B(1)
{
m_B.doSom
Easiest is storing pointers to a B
and a C
. These can be initialized to 0, omitting any construction. Be careful not to dereference a null pointer and delete it in the destructor of A
(or use std::unique_ptr
/boost::scoped_ptr
).
But why not initialize m_B
first (through a proper constructor call, not in A::A()
, and then use that initialized B
instance to initialize m_C
? It will call for a small rewrite, but I bet it'll be worth the code cleanup.