After reading Polymorphism in C++ and What is polymorphism, what is it for, and how is it used? I noticed many answers had differences in what they listed as methods of achieving polymorphism and I wanted to make a list for myself that was more comprehensive.
Mechanisms for Achieving Polymorphism
- Overloading (functions or operators)
- Overriding functions through inheritance (without virtual)
- Virtual functions
- Templates
- Preprocessing (for ex. using
#define
, this was taken from the answer in the first link) - Standard conversions (ex. implicit conversions)
What am I missing or leaving out? Is this list comprehensive enough?
After reading https://catonmat.net/cpp-polymorphism I was also interested in categorizing these mechanisms.
Ad hoc (also known as runtime polymorphism):
- Virtual
- Overriding
Parametric (also known as compile-time polymorphism):
- Templates
Subtyping (also known as overloading)
- Overloading
- Overloading
Coersion (also known as casting)
- Standard conversions
Are these categorizations correct?
For reference: (Taken from https://en.wikipedia.org/wiki/Polymorphism_(computer_science))
The most commonly recognised major classes of polymorphism are:
Ad hoc polymorphism: defines a common interface for an arbitrary set of individually specified types.
Parametric polymorphism: when one or more types are not specified by name but by abstract symbols that can represent any type.
Subtyping (also called subtype polymorphism or inclusion polymorphism): when a name denotes instances of many different classes related by some common superclass.