疑惑

machaoqun6666 2008-08-07 08:53:02
#include <iostream>
class CFenshu
{
int fm,fz;
friend std::ostream & operator<<(ostream& out,const CFenshu& fs);
public
.....
};
std::ostream & operator<<(ostream& out,const CFenshu& fs)
{
out<<fs.fz<<"/"<<fs.fm;
return out;
}
友元为什么不对?
错误信息:declaration of'operator<<'as non-function
新手,请赐教。
...全文
134 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
machaoqun6666 2008-08-07
  • 打赏
  • 举报
回复
非常感谢!
太乙 2008-08-07
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 k2eats 的回复:]
#include <iostream>
using namespace std;
[/Quote]

有时还可以用
#include<iostream.h>

当然,还是上面那个好用!
K行天下 2008-08-07
  • 打赏
  • 举报
回复
#include <iostream>
using namespace std;
Maxwell 2008-08-07
  • 打赏
  • 举报
回复
class CFenshu
{
int fm,fz;
friend std::ostream& operator<<(std::ostream& out,const CFenshu& fs);
};

std::ostream& operator<<(std::ostream& out,const CFenshu& fs)
{
out <<fs.fz <<"/" <<fs.fm;
return out;
}

漏了红字部分。
zeroczh 2008-08-07
  • 打赏
  • 举报
回复
#include <iostream>

class CFenshu
{
int fm,fz;
friend std::ostream & operator <<(std::ostream& out,const CFenshu& fs);
public:
};

std::ostream & operator <<(std::ostream& out,const CFenshu& fs)
{
out <<fs.fz <<"/" <<fs.fm;
return out;
}

int main()
{
return 0;
}
lzr4304061988012 2008-08-07
  • 打赏
  • 举报
回复
#include <iostream> 
using namespace std;
class CFenshu
{
int fm,fz;
friend std::ostream & operator <<(ostream& out,const CFenshu& fs);


};
std::ostream & operator <<(ostream& out,const CFenshu& fs)
{
out <<fs.fz <<"/" <<fs.fm;
return out;
}
xkyx_cn 2008-08-07
  • 打赏
  • 举报
回复

#include <iostream>

using namespace std;

class CFenshu;
ostream & operator<<(ostream& out,const CFenshu& fs);

class CFenshu
{
int fm,fz;
public:
friend ostream & operator<<(ostream& out,const CFenshu& fs);
};

ostream & operator<<(ostream& out,const CFenshu& fs)
{
out << fs.fz << "/" << fs.fm;
return out;
}

int main()
{
CFenshu fs;
cout << fs << endl;

return 0;
}

65,186

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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