Home Segments Index Top Previous Next

385: Mainline

To define a one-dimensional cylinder array, you must define the cylinder class first; then, you can write an array definition, as you would to define any array.

The following statement, for example, is an array definition that tells C++ to allocate memory for a one-dimensional array, named oil_tanks, containing three cylinders:

 *-- Specifies that the array contains cylinder objects 
 | 
 |        *-- Specifies that the name of the array is oil_tanks 
 |        | 
 |        |        *-- Specifies that the array contains three objects 
 v        v        v 
cylinder oil_tanks[3]; 

Thus, an array definition for class objects looks like an ordinary array definition, except that a class name, such as cylinder, appears, instead of the name of a language-defined type, such as int.