Concept of Polymorphism in c++

Definition of Polymorphism

                    "Polymorphism means the ability to take more than one form."

                     It allows a single name to be used for more than one related purpose. It means ability of operators and functions to act differently in different situations. 

Different types of polymorphism are :


-> Compile-Time:
  • Compile time polymorphism is function and operator overloading.


-> Function Overloading
  • Function overloading is the practice of  declaring the same function with different signatures.
  • The same function name will be used with different number of parameters and parameters of different type.
  • Overloading of functions with different return type is not allowed.


-> Operator Overloading
  • Operator overloading is the ability to tell the compiler how to perform a certain operation based on its corresponding operator's data type.
  • Like + performs addition of two integer numbers, concatenation of two string variables and works totally different when used with objects of time class.


-> Dynamic Binding (Late Binding) :
  • Dynamic Binding is the linking of a routine  or object at runtime based on the conditions at that  moment.
  • At run-time, the code matching the object under current reference will be called.


-> Virtual Function
  • Virtual function is a member function of a class, whose functionality can be over-ridden in its derived classes.
  • The whole function body can be replaced with a new set of implementation in the derived class.
  • It is declared as virtual in the base class using the virtual keyword.