开发者

Is it standard C++ to assign a member pointer to the address of another member in the constructor initializer?

开发者 https://www.devze.com 2022-12-29 07:13 出处:网络
Does this 开发者_JS百科conform to the standard? class Foo { Bar m_bar; Bar * m_woo; public: Foo() : m_bar(42, 123), m_woo(&m_bar) { }

Does this 开发者_JS百科conform to the standard?

class Foo {
    Bar m_bar;
    Bar * m_woo;
public:
    Foo() : m_bar(42, 123), m_woo(&m_bar) { }
};


It is correct. What is not correct is dereferencing that pointer before that particular subobject has been fully initialized.

0

精彩评论

暂无评论...
验证码 换一张
取 消