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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.