Sams Teach Yourself C++ in 21 Days

(singke) #1

DAY 14


WEEK 2

Polymorphism


On Day 12, “Implementing Inheritance,” you learned how to write virtual func-
tions in derived classes. This is the fundamental building block of polymor-
phism: the capability to bind specific, derived class objects to base class
pointers at runtime.
Today, you will learn


  • What multiple inheritance is and how to use it

  • What virtual inheritance is and when to use it

  • What abstract classes are and when to use them

  • What pure virtual functions are


Problems with Single Inheritance........................................................................


Suppose you’ve been working with your animal classes for a while, and you’ve
divided the class hierarchy into Birds and Mammals. The Birdclass includes the
member function Fly(). The Mammalclass has been divided into a number of
types of Mammals, including Horse. The Horseclass includes the member func-
tions Whinny()and Gallop().
Free download pdf