What is polymorphism?

What is polymorphism in C++?

1 Like

Polymorphism is the ability to use an operator or function in different ways. Polymorphism gives different meanings or functions to the operators or functions. Poly, referring to many, signifies the many uses of these operators and functions. A single function usage or an operator functioning in many ways can be called polymorphism.

types of polymorphism
ad-hoc polymorphism
parametric polymorphism

run-time polymorphism:

The run-time polymorphism is implemented with inheritance and virtual functions.

compile-time polymorphism:

The compile-time polymorphism is implemented with templates.

ad-hoc polymorphism:

If the range of actual types that can be used is finite and the combinations must be individually specified prior to use, this is called ad-hoc polymorphism.

parametric polymorphism:

If all code is written without mention of any specific type and thus can be used transparently with any number of new types it is called parametric polymorphism.