C++
Programming and Technical
What is Polymorphism??
Read Solution (Total 1)
-
- Polymorphism is a mechanism where the specific definition of a function is bound to a function name depending on data type. The data type may refer to an object pointer or the data type of function parameters.
The word ‘polymorphism’ literally is a composite of the words “many” and “morph” means “form”. From a grammatical point of view, polymorphism is the ability of an object to assume or become many different forms of object.
C++ has 4 distinct forms of polymorphism. These forms of polymorphism are:
• Runtime polymorphism also known as subtype polymorphism (virtual function).
• Compile-time polymorphism also known as parametric polymorphism (template)
• Overloading also known as ad-hoc polymorphism (multiple signatures)
• Coercion (implicit or explicit coercion)
Subtype polymorphism is the ability to use derived classes through base class pointers and references.
Parametric polymorphism provides a means to execute the same code for any type. In C++ parametric polymorphism is implemented via templates. Templates make generic programming possible. Since parametric polymorphism happens at compile time, it's also called compile-time polymorphism.
Overloading is an ad-hoc form of polymorphism. Overloading is the declaration of functions all having the same name and return type but different parameters. The parameter set for each different declaration is known as a signature.
In ad hoc polymorphism, each function name effectively designates different code blocks to be executed although the semantics are very similar in the eyes of the programmer. - 6 years agoHelpfull: Yes(0) No(0)
C++ Other Question