聚合数据类型

称为 aggregates(聚合物)

聚合类型包括: - array type - class type (typically, struct or union), that has - no private or protected direct (since C++17)non-static data members - no user-declared constructors(until C++11) - no user-providedinherited, or explicit constructors (since C++11) (until C++20) - no user-declared or inherited constructors(since C++20) - no virtual, private, or protected (since C++17) base classes - no virtual member functions - no default member initializers (since C++11) (until C++14)

聚合类型中元素的特点 - for an array, the array elements in increasing subscript order, or - for a class, the non-static data members that are not anonymous bit-fields, in declaration order.(until C++17) - for a class, the direct base classes in declaration order, followed by the direct non-static data members that are neither anonymous bit-fields nor members of an anonymous union, in declaration order.(since C++17)

C++ 中的聚合数据类型必须满足如下条件:

  • 是一个类类型(包括 struct, class 或 union) 或数组 (包括内置数组或std::array);
  • 没有私有或受保护的非静态数据成员;
  • 没有用户声明的或继承的构造函数
  • 没有基类
  • 没有虚函数