Home Segments Index Top Previous Next

231: Mainline

To specify a class's superclasses, you insert a colon, the symbol public, and name of the superclass just after the name of the class in the class's definition:

class class name : public superclass name { 
  ... 
}; 

For example, as you define the box class, you specify that container is a superclass as follows:

class box : public container {       
  public: double height, width, length; 
          // Default constructor: 
          box ( ) { } 
          // Other member function: 
          double volume ( ) {return height * width * length;} 
}; 

Note that the box class now contains the member variables and the member function formerly found in the box_car class.