哪位大哥帮我看看这个程序哪里有问题?

[复制链接]
查看11 | 回复1 | 2010-9-20 16:31:11 | 显示全部楼层 |阅读模式
#include //这个程序有问题(september 1246)
using namespace std;
class point
{
private:
int xpos;
int ypos;
public:
point(int x=0,int y=0)
{
xpos=x;
ypos=y;
}
void disp()
{
cout<<"("<<xpos<<" ,"<<ypos<<")"<<endl;
}
int getx()
{
return xpos;
}
int gety()
{
return ypos;
}
};
class point3D:public point
{
private:
int zpos;
private:
point3D(int x,int y,int z):point(x,y)
{
zpos=z;
}
void disp()
{
cout<<"("<<getx()<<", "<<gety()<<", "<<zpos<<")"<<endl;
}
int calcsum()
{
return getx()+gety()+zpos;
}

};
int main()
{
point pt1(7,8);
pt1.disp();
point3D pt2(3,4,5);
pt2.disp();
int res=pt2.calcsum();
cout<<res<<endl;
return 0;
}

回复

使用道具 举报

千问 | 2010-9-20 16:31:11 | 显示全部楼层
我就把一个private改成public了,不知道楼主怎么看:#include //这个程序有问题(september 1246)using namespace std;class point{private: int xpos; int ypos;public: point(int x=0,int y=0) {xpos=x;ypos=y; } void disp() {cout<<"("<<xpos<<" ,"<<ypos<<")"<<endl; } int getx() {return xpos; } int gety()
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行