c++高手帮忙看个程序啊!!!急!!!

来源:百度知道 编辑:UC知道 时间:2024/09/28 12:49:05
#include<iostream.h>
class Shape
{public:
Shape(){}
~Shape(){}
virtual float GetArea(){return -1;}
};
class Circle:public Shape
{public:
Circle(float radius): itsRadius(radius){}
~Circle(){}
double GetArea(){return 3.1415926*itsRadius*itsRadius;}
private:
float itsRadius;
};
class Ractangle:public Shape
{
public:
Rectangle(float len,float width):itsLength(len),itsWidth(width){};
~Rectangle(){};
virtual float GetArea(){return itsLength*itsWidth;}
virtual float GetLength(){return itsLength;}
virtual float GetWidth(){return itsWidth;}
private:float itsWidth; float itsLength;
};
class Square:public Rectangle
{
public:Square(float len);
~Square(){}
};
Square::Square(float len):
Rectangle(len,len){}
int main()
{
Shape*sp;
sp=new Circle(5);
cout<<"The area of the Circle is"<&l

错误1.基类的虚函数返回类型为Float,但是你在派生类里重定义的时候却弄成了Double类型,所以出错.应该让函数的返回类型一致.
错误2:类名定义为Ractangle,但你使用的时候却是Rectangle,猜测你的意思,应该是你定义类名的时候英语单词写错了.呵呵
因此你只用改掉这两个就可以运行了,我测试了,可以通过.