Copy constructor curly braces initialization

后端 未结 1 586
抹茶落季
抹茶落季 2020-12-19 07:14

\"we can initializate objects of a class for which we have not define any constructor using:

  • memberwise initialization.
  • copy
1条回答
  •  醉梦人生
    2020-12-19 07:51

    I think the behaviour conforms with 8.5.4 (List initialization), sentence 3:

    List-initialization of an object or reference of type T is defined as follows:

    — If T is an aggregate, aggregate initialization is performed (8.5.1).

    [...]

    — Otherwise, if the initializer list has a single element of type E [...] the object or reference is initialized from that element;

    You were expecting the second item in my abbreviated quote to apply, but the first item takes precedence: Since Data is indeed an aggregate, the one-element-list clause is never considered.


    Your quote from the book appears to be a known error. The language is allegedly going to be fixed to match the book in C++14.

    0 讨论(0)
提交回复
热议问题