Hour 18. Making Use of Advanced Polymorphism
Problems with Single Inheritance
In the previous hours, we discussed treating derived objects polymorphically with their base classes. You saw that if the base class has a member function speak()
that is overridden in the derived class, a pointer to a base object that is assigned to a derived object will do the right thing. The Mammal12 program in Listing 18.1 illustrates this idea.
1: #include <iostream> 2: 3: class Mammal 4: { 5: public: 6: Mammal():age(1) { std::cout << "Mammal constructor ...\n"; ...
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.