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

Does this comply with the standard?

class Foo {
    Bar m_bar;
    Bar * m_woo;
public:
    Foo() : m_bar(42, 123), m_woo(&m_bar) { }
};
+3
source share
1 answer

It is right. What is wrong is the dereferencing of what the pointer is before this particular subobject has been fully initialized.

+4
source

Source: https://habr.com/ru/post/1744026/


All Articles