Lesson 15: Inheritance, Polymorphism, and Virtual Functions
Lesson 15: Inheritance, Polymorphism, and Virtual Functions
Square::Square(int side):Rectangle(side,side)
void Y();
DerivedClass D;
D.X();
The function
is now virtual.
class class
square rectSolid
class
cube
CS1 -- Inheritance and Polymorphism 47
Multiple Inheritance
• Problem: what if base classes have member
variables/functions with the same name?
• Solutions:
– Derived class redefines the multiply-defined
function
– Derived class invokes member function in a
particular base class using scope resolution
operator ::
• Compiler errors occur if derived class uses
base class function without one of these
solutions
CS1 -- Inheritance and Polymorphism 48