简体   繁体   English

在构造函数初始化程序中为成员指针指定另一个成员的地址是标准C ++吗?

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

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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM