Share via


Initializing Aggregates

An aggregate type is an array, class, or structure type which:

  • Has no constructors

  • Has no nonpublic members

  • Has no base classes

  • Has no virtual functions

Initializers for aggregates can be specified as a comma-separated list of values enclosed in curly braces. For example, this code declares an int array of 10 and initializes it:

int rgiArray[10] = { 9, 8, 4, 6, 5, 6, 3, 5, 6, 11 };

The initializers are stored in the array elements in increasing subscript order. Therefore, rgiArray[0] is 9, rgiArray[1] is 8, and so on, until rgiArray[9], which is 11. To initialize a structure, use code such as:

// initializing_aggregates.cpp
struct RCPrompt
{
short nRow;
short nCol;
char *szPrompt;
};
int main()
{
RCPrompt rcContinueYN = { 24, 0, "Continue (Y/N?)" };
}

See Also

Reference

Initializers