初学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;
}
红色部分不太理解,帮忙解释一下
输出结果:??????????