Aggregates in C++
An aggregate class gives users direct access to its members and has special initialization syntax. A class is an aggregate if
- All of its data members are public,
- It does not define any constructors,
- It has no in-class initializers, and
- It has no base classes or virtual functions, which are class-related features that we’ll cover in Chapter 15,
For example, the following class is an aggregate:
struct Data { int ival; string s; };
We can initialize the data members of an aggregate class by providing a braced list of member initializers:
Data val1 = { 0, "Anna"};