C++ Programming

From Wikibooks, open books for an open world
Jump to navigation Jump to search
Polymorphism[edit | edit source]

Polymorphism allows a single name to be reused for several related but different purposes. The purpose of polymorphism is to allow one name to be used for a general class. Depending on the type of data, a specific instance of the general case is executed.

The concept of polymorphism is wider. Polymorphism exists every time we use two functions that have the same name, but differ in the implementation. They may also differ in their interface, e.g., by taking different arguments. In that case the choice of which function to make is via overload resolution, and is performed at compile time, so we refer to this as static polymorphism.

Dynamic polymorphism will be covered deeply in the Classes Section where we will address its use on redefining the method in the derived class.