Is the order of initialization guaranteed by the standard?

后端 未结 5 509
情书的邮戳
情书的邮戳 2020-12-31 12:44

In the following code snippet d1\'s initializer is passed d2 which has not been constructed yet (correct?), so is the d.j in D\'s copy constructor an uninitialized memory ac

5条回答
  •  我在风中等你
    2020-12-31 13:06

    This phenomenon is explained/highlighted in Item 13 of Meyer's Effective C++. It says that the destructor must destroy elements in the inverse order of its constructors, therefore all constructors must initialize elements in the same order, therefore they initialize them in the order in which they're declared (instead of the sequence of the initialization lists).

提交回复
热议问题