13.2 COMPILE TIME POLYMORPHISM

Earlier, we have stated that polymorphism means different behaviour by different objects for the function with same name. The function can be in the base class or in the derived class. When compiler decide which function to call at the time of compilation (strictly speaking before execution of program starts), it is termed as compile time polymorphism.

We will illustrate this with Programs 13.1 and 13.2.

13.2.1 Polymorphism with ordinary1 objects

Program: Write a program to study polymorphism. Use the following specifications: Create a base class called creatures. It should have a constructor and method move to tell about how that creature moves. The data member should be a character array for storing the name of ...

Get Object Oriented Programming with C++, Second 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.