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

StackOverflow https://stackoverflow.com/questions/2767403

문제

Does this 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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top