Home Segments Index Top Previous Next

230: Mainline

Once you have decided where member variables and member functions should be declared and defined, you can proceed to define classes and to link them up in a hierarchy.

You can define the container and railroad_car classes readily, because neither is a subclass of any other class:

int current_year = 2001; 
class container { 
  public: int percent_loaded; 
          // Default constructor: 
          container ( ) { } 
}; 
class railroad_car { 
  public: int year_built; 
          // Default constructor: 
          railroad_car ( ) { } 
          // Other member function: 
          int age ( ) {return current_year - year_built;} 
};