Initializing Aggregates

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

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?)" };
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2015 Microsoft