Home Segments Index Top Previous Next

182: Mainline

To tell the C++ compiler to use the two-parameter constructor, blocking the involvement of the default constructor, you modify your tank_car variable declaration as follows:

 *----- Declare t to be a variable of class tank_car 
 | 
 |             *----- Add argument list with two arguments 
 |             | 
 |             v 
 v         ----------- 
tank_car t (3.5, 40.0); 

The parameters dictate that initialization is not to be done by the default constructor, because default constructors never have arguments. The default constructor is called whenever there is no argument list, as in the statement tank_car t;. The other, two-parameter constructor is called when there is an argument list, as in tank_car t (3.5, 50.0).