Hour 17. Using Polymorphism and Derived Classes

Polymorphism Implemented with Virtual Methods

The previous hour emphasized the fact that a Dog object is a Mammal object. This meant that the Dog object inherited the attributes (data) and capabilities (member functions) of its base class. The relationship between a base class and derived class runs deeper than that in C++.

Polymorphism allows derived objects to be treated as if they were base objects. For example, suppose you create specialized Mammal types ...

Get Sams Teach Yourself C++ in 24 Hours, fifth edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.