C++ 多态
c++ 多态
多态按字面的意思就是多种形态。当类之间存在层次结构,并且类之间是通过继承关联时,就会用到多态。
c++ 多态意味着调用成员函数时,会根据调用函数的对象的类型来执行不同的函数。
下面的实例中,基类 shape 被派生为两个类,如下所示:
#include
using namespace std;
class shape {
protected:
int width, height;
public:
shape( int a=0, int b=0)
{
width = a;
height = b;
}
int area()
{
cout << "parent class area :" < 

