C++: Constructor versus initializer list in struct/class

前端 未结 2 455
梦如初夏
梦如初夏 2021-01-12 01:11

An object of a struct/class (that has no constructor) can be created using an initializer list. Why is this not allowed on struct/class wit

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-12 01:46

    No, an object with a constructor is no longer considered a POD (plain old data). Objects must only contain other POD types as non-static members (including basic types). A POD can have static functions and static complex data members.

    Note that the upcoming C++ standard will allow you to define initializer lists, which will allow non-POD objects to be initialized with braces.

提交回复
热议问题