What is polymorphism in C + +
Introduction
Polymorphism (polymorphism), Encapsulation (encapsulation) and inheritance (inheritance) are the "three features" of object-oriented thinking, commonly known as " object-oriented kick ", and polymorphism is the most powerful kill in kick, is an object-oriented, the most subtle internal strength, it can be said, do not understand polymorphism does not know what is object-oriented.
Defined
The same action acts on different objects, can have different interpretations, and produces different execution results.
Simply generalize as "one interface, multiple methods".
Category
(1) Polymorphism at compile time.
?? The compile-time polymorphism is implemented by overloading . For non-virtual members, the system compiles, depending on the parameters passed, the type of return, and other information to decide what to do. (Refer to my post, "function overloading in C + +")
(2) The polymorphism of the runtime.
?? Runtime polymorphism means that the operation is not determined according to the actual situation until the system is running. In C + +, run-time polymorphism is implemented through virtual members .
Role
The purpose of polymorphism is to reuse the interface . In other words, regardless of what is passed to the object of that class, functions can be called through the same interface to adapt to the implementation of the respective object.
Copyright NOTICE: This article for csdn bo Master [Applebite] (Http://blog.csdn.net/applebite) original articles, reproduced please indicate the source, infringement must be studied.
What is polymorphism in C + +