Polymorphism means “many forms”. It is where one type of thing comes in many forms. So you can treat it according to its type, but it will behave differently according to which form of that type it happens to be.


Polymorphism stems from inheritance. The whole idea is that you have a general base class and more specific derived classes. You can then write code that works with the base class… and polymorphims makes your code not only work with the base class, but all derived classes.


One of the features of derived classes is that a pointer to a derived class is type-compatible with a pointer to its base class. Polymorphism takes advantage of this feature.


A class that declares or inherits a virtual function is called a polymorphic class.

Polymorphism class是定义或继承了virtual functionclass

Pure virtual function定义:

virtual void f() = 0;

包含pure virtual function定义的类是abstract class

I don’t understand Polymorphism at all?
C++ polymorphism and abstract base class



电子邮件地址不会被公开。 必填项已用*标注