Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Intermediate
Aug 13, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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 aggregates
Employee emp = {0}; //all emp members are zero-initialized
Employee 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.

Danny Kalev
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date