Avoid calling constructor of member variable

后端 未结 9 1615
礼貌的吻别
礼貌的吻别 2021-02-19 13:14

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         


        
9条回答
  •  Happy的楠姐
    2021-02-19 14:16

    The pointer sounds like the only clean solution to me. The only other solution I see is to have a default constructor for C that does nothing and have an initialising method in C you call yourself later.

    m_C.Initialise( m_B.getSomeValue() );

提交回复
热议问题