不知道为什么程序报错
#include<iostream>
#include<string>
using namespace std;
class Shape{
public:
Shape();
virtual ~Shape();
virtual double calcArea(){
cout<<"Shape---calcArea()"<<endl;
return 0;
}
};
Shape::Shape(){
cout<<"Shape()"<<endl;
}
Shape::~Shape(){
cout<<"~Shape()"<<endl;
}
class Circle:public Shape{
protected:
double r;
Coordinate *pCenter;
public:
Circle(double _r);
virtual ~Circle();
virtual double calcArea(){
cout<<"Circle---calcArea()"<<endl;
return 3.14*r*r;
}
};
Circle::Circle(double _r){
r=_r;
pCenter=new Coordinate(3,5);
cout<<"Circle"<<endl;
}
Circle::~Circle(){
delete pCenter;
pCenter=NULL;
cout<<"~Circle()"<<endl;
}
class Rect:public Shape{
protected:
double width;
double height;
public:
Rect(double _width,double _height);
virtual ~Rect();
virtual double calcArea(){
cout<<"Rect---calcArea()"<<endl;
return width*height;
}
};
Rect::Rect(double _width,double _height){
width=_width;
height=_height;
cout<<"Rect()"<<endl;
}
Rect::~Rect(){
cout<<"~Rect()"<<endl;
}
class Coordiante{
private:
int x;
int y;
public:
Coordinate(int _x,int _y);
~Coordinate();
};
Coordinate(int _x,int _y){
cout<<"Coordinate()"<<endl;
x=_x;
y=_y;
}
Coordinate::~Coordinate(){
cout<<"~Coordinate()"<<endl;
}
int main(){
Shape *shape1=new Rect(5,6);
Shape *shape2=new Circle(5);
shape1->calcArea();
shape2->calcArea();
delete shape1;
shape1=NULL;
delete shape2;
shape2=NULL;
return 0;
}