What are Aggregates?

What are Aggregates?

The term “aggregate” is used in the ANSI standard to denote an array or a class with no constructors, no private or protected data members, no base classes, and no virtual functions. In other words, an aggregate is a POD (plain old data object or an array thereof, see also What are Plain Old Data (POD) Objects?.

Aggregates differ from objects and arrays of object in several ways. In particular, you can initialize every aggregate of every type and size by the ‘={0};’ initializer list. This initializer list guarantees that the entire aggregate is zero-initialized:

 struct Employee{  int ID;  int rank  char name[12];  int salary;};  // using the  '={0}' initializer to initialize aggregatesEmployee emp = {0}; //all emp members are zero-initializedEmployee emp_arr[10] = {0}; //all array elements are zero-initialized

Note that non-aggregate objects and arrays cannot be initialized this way; instead, they are initialized by a constructor.

See also  The Benefits of Patient Engagement Solutions for Healthcare Providers

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist