# 求高人指教：分析一下以下代码的执行过程

0

#include <iostream>

using namespace std;

class Shape

{

public:     Shape(){}

virtual ~Shape() {}

virtual float Area() const=0;

virtual Shape * Clone() const=0;

};

class Circle:public Shape

{

virtual ~Circle()              {}

virtual float Area() const

}

virtual Circle * Clone() const {return new Circle(*this); }

private:

Circle(const Circle& rhs)

{             cout<<"Copy Construct Circle!"<<endl;

}

};

class Rectangle:public Shape

{

public:

Rectangle(float w,float h):width(w),height(h) {}

virtual ~Rectangle()              {}

virtual float Area() const

{  cout<<"Rectangle's Area ="<<width*height<<endl;

return width*height;

}

virtual Rectangle * Clone() const

{return new Rectangle(*this); }

private:

Rectangle(const Rectangle& rhs)

{  cout<<"Copy Construct Rectangle!"<<endl;             width=rhs.width;height=rhs.height;

}

private:

float width;

float height;

};

int main(int argc, char* argv[])

{

Shape * p1=new Circle(2.5);

p1->Area();

Shape * p2=new Rectangle(5,11);

p2->Area();

Shape *p3=p1->Clone();

p3->Area();

Shape *p4=p2->Clone();

p4->Area();

delete p4;

delete p3;

delete p2;

delete p1;

return 0;

}

您需要登录以后才能回答，未注册用户请先注册