O'Reilly logo

Navigating C++ and Object-Oriented Design by Gail Anderson, Paul Anderson

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

5.6. Arrays of Class Objects

C++ arrays may contain objects as well as built-in types. Two formats allocate memory for class object arrays from either the stack or data area.

					Type name[size] = { init_list }; 
Type name[size1][size2][sizeN] = { init_list };

The rules for size are the same as the rules for arrays of built-in types (see “Arrays” on page 35). The optional brace-enclosed init_list typically contains constructors to build each object in the array. If you do not initialize an array, the compiler calls default constructors to initialize each array element. When you initialize arrays of class objects, you must include braces with init_list.

Likewise, two formats with operator new allocate memory for dynamic class object arrays in free ...

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