Home Segments Index Top Previous Next

223: Mainline

Fortunately, C++ encourages you to cut down on duplication, thereby easing program writing, debugging, and maintenance, by allowing you to arrange class definitions in hierarchies that reflect natural category hierarchies.

Using C++, you can say, for example, that box cars, tank cars, engines, and cabooses are railroad cars. Then, you can declare a year_built member variable and an age member function in the railroad_car class alone, because the year_built member variable will appear in each individual box car, tank car, engine, and caboose object, and the age member function will be available to all those railroad_car objects as though age had been declared four times.