请大家教我怎样改正这样的C++程序错误

来源:百度知道 编辑:UC知道 时间:2024/06/04 18:59:35
#include <iostream>
#include <cmath>
#define PI 3.1415926
using namespace std;
class Point
{
public:
Point(float x,float y)
{
X=x;
Y=y;
}
float Getx()
{
return X;
}
float Gety()
{
return Y;
}
private:
float X;
float Y;
};
class Rectangle: public Point
{
public:
Rectangle(float a,float b,float x,float y):Point(x,y)
{
A=a;
B=b;
}
float Area()
{
return abs((x-a))*abs((y-b));
}
private:
float A;
float B;
};
class Circle:public Point
{
public:
Circle(float r,float x,float y):Point(x,y)
{
R=r;
}
float Area()
{
return PI*r*r;
}
private:
float R;
};
void main()
{
Rectangle R(1,2,3,4);
Circle C(2,1,1);
cout << R.Area() <<endl;
cout &l

改成这样
float Area()
{
return abs((Getx()-A))*abs((Gety()-B));
}

float Area()
{
return (float)PI*R*R;
}

不可能,我用VC++2005编译通过了

1>------ 已启动全部重新生成: 项目: 1111, 配置: Debug Win32 ------
1>正在删除项目“1111”(配置“Debug|Win32”)的中间文件和输出文件
1>正在编译...
1>1.cpp
1>正在编译资源清单...
1>正在链接...
1>LINK : 没有找到 F:\project\1111\Debug\1111.exe 或上一个增量链接没有生成它;正在执行完全链接
1>正在嵌入清单...
1>生成日志保存在“file://f:\project\1111\1111\Debug\BuildLog.htm”
1>1111 - 0 个错误,0 个警告
========== 全部重新生成: 1 已成功, 0 已失败, 0 已跳过 ==========

问题是你在派生类中使用了基类的私有成员;不管如何继承,基类的私有成员派生类都是无法访问的。
这是改后的代码,VC6.0已经通过:

#include <iostream>
#include <cmath>
#define PI 3.1415926
using namespace std;
class Point
{
public:
Point(float x,float y)
{
X=x;
Y=y;
}
float Getx()
{
ret