C ++构造函数Const成员赋值

时间:2015-09-03 23:52:23

标签: c++

我有一个带有一些指向对象的常量指针的类。 const值构造函数的执行顺序是什么,它们何时被赋值?查看以下代码可能会更有意义。

class Foo
{
public:
    Child2* const m_Child2;
    Child1* const m_Child1;

    Foo() : 
        m_Child1(new Child1(*this)),
        m_Child2(new Child2(*this))
    {}
};


class Child2
{
public:
    Child2(Foo& Parent)
    {
        Parent.m_Child1; 
            // this value is still `nullptr` even though it should
            // have been created before this constructor call
    }
}

Foo::m_Child2的构造函数是否可以访问构造的对象Foo::m_Child1

0 个答案:

没有答案
相关问题