大家帮忙看一下到底什么问题?

lbl023 2005-12-09 08:08:39
#include<iostream>
class point
{
public:
point(float,float);
void setpoint(float,float);
float getX() const {return x;}
float getY() const {return y;}
friend ostream &operator<<(ostream &,const point &);
protected:
float x;
float y;
};
point::point(float a,float b)
{
x=a;
y=b;
}
void point::setpoint(float a,float b)
{
x=a;
y=b;
}
ostream &operator<<(ostream &output,const point &p)
{
output<<"["<<p.x<<","<<p.y<<"]"<<endl;
return output;
}
int main()
{
point p(3.5,6.4);
cout<<"x="<<p.getX()<<",y="<<p.getY()<<endl;
p.setpoint(8.5,6.8);
cout<<"p(new):"<<p<<endl;
}
...全文
117 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
lbl023 2005-12-10
  • 打赏
  • 举报
回复
我到CSDN来是寻求帮忙,请教问题的解决方法的.想看到的回复当然也是所提问的相关答案,至于那些所谓的高手,要解决大难题的.至于我的小问题不感兴趣的话我也不会勉强,但我还是希望进来看帖的朋友都能给我的问题做一些帮助性的发表.在此先谢!最后要对那些做出了实在帮助的朋友再道声谢.当然以后我在提问时也会尽量把提问说明确些.
hacker88 2005-12-09
  • 打赏
  • 举报
回复
呵呵,上面这位是想考考我们的水平是不??这里面除了我之外高手如云,考也拿个有难度点来,给大家看看哈
csucdl 2005-12-09
  • 打赏
  • 举报
回复
是啊, 又不说你要干什么
cunsh 2005-12-09
  • 打赏
  • 举报
回复
#include<iostream>
using namespace std;
class point;
ostream & operator<<(ostream &,const point &);
class point
{
public:
point(float,float);
void setpoint(float,float);
float getX() const {return x;}
float getY() const {return y;}
friend ostream &operator<<(ostream &,const point &);
protected:
float x;
float y;
};
point::point(float a,float b)
{
x=a;
y=b;
}
void point::setpoint(float a,float b)
{
x=a;
y=b;
}
ostream &operator<<(ostream &output,const point &p)
{
output<<"["<<p.x<<","<<p.y<<"]"<<endl;
return output;
}
int main()
{
point p(3.5,6.4);
cout<<"x="<<p.getX()<<",y="<<p.getY()<<endl;
p.setpoint(8.5,6.8);
cout<<"p(new):"<<p<<endl;
}

/*
x=3.5,y=6.4
p(new):[8.5,6.8]

Press any key to

*/
xiaocai0001 2005-12-09
  • 打赏
  • 举报
回复
修改方案一:

#include<iostream>
改为
#include<iostream.h>

修改方案二:

#include<iostream>
下面添上一句
using namespace std;
如果还有错, 则需要将
friend ostream &operator<<(ostream &,const point &);
改为
friend ostream &std:operator<<(ostream &,const point &);

修改方案三:
将所有的ostream 用std::ostream替换,
同样, 若还有错误, operator 写成std::operator
guyanhun 2005-12-09
  • 打赏
  • 举报
回复
加个 using namespace std; 啊
xiaocai0001 2005-12-09
  • 打赏
  • 举报
回复
楼主问问题时, 要把问题描述清楚, 是你在问问题, 不是在让我们找错.
xiaocai0001 2005-12-09
  • 打赏
  • 举报
回复
很显然少了个
using namespace std;
EnginePlus 2005-12-09
  • 打赏
  • 举报
回复
ostream &operator<<(ostream &output,const point &p)
{
output<<"["<<p.x<<","<<p.y<<"]"<<endl;
~~~~~~~~~~~~~~~~~~~~~~~~~~
??啥意思?
return output;
}

还有 setpoint 和 point 2个函数重复了

point() 里写 setpoint (a,b) 就好啦

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧