c++ 不太懂得地方

class Shape
{
public:
virtual void display(){
cout<<"shape"<<endl;
}
};
class Circle:public Shape
{
public:
void display()
{
cout<<"circle"<<endl;
}

};
class Rect:public Shape
{
public:
void display(){
cout<<"rect"<<endl;
}

};

void main()
{
Shape a;
Circle b;
Rect c;

a.display();
b.display();
c.display();

Shape *p=new Shape[3];
p[0]=a;
p[1]=b;
p[2]=c;

for(int i=0;i<3;i++)
p[i].display();
delete []p;

}

输出结果:

shape

circle

rect

shape

shape

shape

不太懂指针那块

原文地址:https://www.cnblogs.com/flashweb/p/2832001.html