Home Segments Index Top Previous Next

626: Mainline

Note that the definition of a one-parameter box_car constructor makes use of both the one-parameter railroad_car constructor and, separated by a comma, the three-parameter box constructor. The box_car constructor establishes dimensions, and the railroad_car constructor records the serial number:

class box_car : public railroad_car, public box {
  public: // Constructors:
          box_car ( ) : box (10.5, 9.5, 40.0) { }
          box_car (char *input_buffer) : railroad_car (input_buffer), 
                                         box (10.5, 9.5, 40.0)        
            { }                                                       
          // Displayers: 
          virtual char* short_name ( ) {return "box";} 
          virtual double capacity ( ) {return volume ( );} 
}; 

Also note that, as a matter of good programming practice, the definition contains not only the one-parameter constructor, but also a default, zero-parameter constructor.