Chapter 3 - Inheritance, Polymorphism, Virtual Functions
Chapter 3 - Inheritance, Polymorphism, Virtual Functions
Square::Square(int side):Rectangle(side,side)
15-22
Derived Class
15-23
From Program 15-7
Problem with Redefining
void Y();
DerivedClass D;
D.X();
Polymorphism and
Virtual Member Functions
Virtual member function: function in base class that
expects to be redefined in derived class
Function defined with key word virtual:
virtual void Y() {...}
Supports dynamic binding: functions bound at run
time to function that they call
Without virtual member functions, C++ uses static
(compile time) binding
Virtual Functions
class class
square rectSolid
class
cube
Multiple Inheritance