Polymorphism

Polymorphism gives us a way to use a class exactly like its parent so there is no confusion with mixing types.

We can treat objects of similar kinds in a uniform way.

There are 2 types of polymorphism in C++:

  1. Compile Time Polymorphism (achieved through Function Overloading)
  2. Runtime Polymorphism (achieved through Virtual Function and Function Overriding)

Compile-Time Polymorphism vs. Runtime Polymorphism

Thanks to polymorphism, we can do some really cool things with pointers (and that’s actually one of the main use cases of Pointers). See Static vs. Dynamic Type Pointer.

Example from https://www.tutorialspoint.com/cplusplus/cpp_polymorphism.htm