In C++ aggregate initialization can be done as T object = { arg1, arg2, ...} or T object{arg1, arg2, ...}. Designated initializers are supported since C++20.

Aggregate

An aggregate is one of the following types:

  • array
  • class, but it should follow these restrictions
    • Constructors
      • For C++11: Can’t have any user-declared, inherited or explicit constructors
      • For C++20: Can’t have any user-declared or inherited constructors
    • No private or protected non-static data members
    • Base classes:
      • Till C++17: no base classes
      • Since C++17: no private or protected base classes. No irtual base classes

Element

An element of an aggregate for a class is non-static members in declaration order. Since C++17, aggregates can have public base classes. So the elements will be direct base classes in declaration order followed by non-static members in declaration order.