这是错误的代码:
#include
using namespace std;
class Point
{
private:
int X, Y;
public:
Point(int X = 0, int Y = 0)
{
this->X = X, this->Y = Y;
}
void move(int OffX, int OffY)
{
X += OffX, Y += OffY;
}
void ShowXY()
{
cout << "(" << X << "," << Y << ")" << endl;
}
};
const double PI = 3.14159;
class Circle :private Point
{
private:
double radius; //半径
public:
Circle(double R, int X, int Y) :Point(X, Y)
{
radius = R;
}
double area()
{
return PI * radius * radius;
}
void ShowCircle()
{
cout << "Centre of circle:";
ShowXY();
cout << "radius:" << radius << endl;
}
void move(int OffX, int OffY)
{
Point::move(OffX, OffY);
}
};
int main()
{
Circle Cir1(10, 100, 200);
Cir1.ShowCircle();
cout << "area is:" << Cir1.area() << endl;
Cir1.move(10, 20);
Cir1.ShowXY(); //错误出在这
return 0;
}
而在 Cir1.ShowXY();前加入//就能正确运行
求解//起到什么作用!