Skip to Main Content
Sams Teach Yourself C++ in 24 Hours, fifth edition
book

Sams Teach Yourself C++ in 24 Hours, fifth edition

by Jesse Liberty, Rogers Cadenhead
April 2011
Beginner content levelBeginner
464 pages
9h 18m
English
Sams
Content preview from Sams Teach Yourself C++ in 24 Hours, fifth edition

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.

Listing 18.1 The Full Text of Mammal12.cpp

 1: #include <iostream> 2: 3: class Mammal 4: { 5: public: 6:     Mammal():age(1) { std::cout << "Mammal constructor ...\n"; ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Sams Teach Yourself C++ in 24 Hours, Sixth Edition

Sams Teach Yourself C++ in 24 Hours, Sixth Edition

Rogers Cadenhead, Jesse Liberty

Publisher Resources

ISBN: 9780672331855Purchase book