[求助]程序报错!!何解!!
#include<iostream> #include<math.h> using namespace std;
class Point{ public: int x,y; Point(int a,int b){x=a;y=b;} Point(){} virtual int length()=0; ~Point(){} };
class Line:public Point{ public: int y2; Line(int a,int b,int c):Point(a,b){y2=c;} Line(){} int length(){return abs(y2-y);} ~Line (){} };
class Rectangle:public Line{ public: int x2; Rectangle(int a,int b,int c,int d):Line(a,b,c){x2=d;} Rectangle(){} int length(){return 2*(abs(y2-y)+abs(x2-x));} ~Rectangle(){} };
void main(){ Point *pp[2]; pp[0]=new Line(3,4,5); pp[1]=new Rectangle(6,7,8,9); for(int i=0;i<3;i++){ cout<<pp[i]->length()<<endl; } }
编译没问题 问题是运行时会提示“执行程序遇到问题需要关闭”
这是为什么!?