![]() |
![]() |
![]() |
![]() |
![]() |
|
In Chapter 15, you learned about box and box_car
classes defined such that the box class contains the height,
width, and length member variables that are initialized by
the default constructor contained in the box_car class:
class box : public container {
public: double height, width, length;
// Default constructor:
box ( ) { }
// Other member function:
double volume ( ) {return height * width * length;}
};
...
class box_car : public railroad_car, public box {
public: // Default constructor:
box_car ( ) {
height = 10.5; width = 9.2; length = 40.0;}
};
The box class, however, can have its own constructor for
initializing its own member variables:
class box : public container {
public: double height, width, length;
// Default constructor:
box ( ) { }
// Argument-bearing constructor:
box (double h, double w, double l) {
height = h; width = w; length = l;
}
// Other member function:
double volume ( ) {return height * width * length;}
};
Given such an argument-bearing constructor in the box class, naturally
you would like to have a way to make use of it in the definition of the
default constructor defined in the box_car class.