[求助]关于虚函数的内容
#include<iostream>using namespace std;
const float PI=(float)3.1416
class Shape()
{
public:
Shape();
~Shape();
virtual float GetArea(){return 0;}
};
class Rectangle:public Shape
{
public:
Rectangle(int wid,int len):width(wid),lenth(len){}
~Rectangle(){}
float GetArea(){return width*lenth;}
private:
float width;
float lenth;
};
class Circle:public Shape
{
public:
Circle(float r):raduis(r){}
~Circle(){}
float GetArea(){return PI*raduis*raduis;}
private:
float raduis;
};
class Square:public Rectangle
{
public:
Square(float len):Rectangle(len,len){}
~Square(){}
};
void main()
{
Shape *ptr;
ptr=new Rectangle(5,9);
cout<<"The area of the Rectangle is "<<ptr->GetArea()<<endl;
delete ptr;
ptr=new Circle(5);
cout<<"The area of the Circle is "<<ptr->GetArea()<<endl;
delete ptr;
ptr=new Square(6);
cout<<"The area of the Square is "<<ptr->GetArea()<<endl;
delete ptr;
}
有哪位看一下,里面的错误查不出来....