O'Reilly logo

C++ Primer, Fifth Edition by Barbara E. Moo, Josée Lajoie, Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

7.5.5. Aggregate Classes

Image

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 (§ 2.6.1, p. 73)

• 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:

// val1.ival = 0; val1.s = string("Anna")Data val1 = { 0, "Anna" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required