武藤写真机报错代码_代码有错不知道如何改?
#include<iostream.h>
#define PI 3.14159
class Shape
{public:
virtual void printArea() = 0;
};
class Circle : public Shape
{public:
Circle(float Radius)
{
mRadius = Radius;
}
void printArea()
{
cout<<"The Circle's Area is "<<PI*mRadius*mRadius<<endl;
}
private:
float mRadius;
};
class Rectangle : public Shape
{public:
Rectangle(float Length, float Height)
{
mLength = Length;
mHeight = Height;
}
void printArea()
{
cout<<"The Rectangle's Area is "<<mLength*mHeight<<endl;
}
private:
float mLength, mHeight;
};
int main()
{
Circle mCircle(2.0);
mCircle.printArea();
Rectangle mRectangle(3.0, 4.0);
mRectangle.printArea();
return 0;
}
最佳答案
头文件包含改为 #include <iostream>
另外请使用std命名空间using namespace std;
你的那些cout、endl都是在命名空间里面的,如果不使用命名空间,就需要std::cout这样用
其他回答
暂无其它回答!