求助 关于重载运算符

菜鸟2333号 2018-04-18 10:34:32
Class X{
.....
friend ostream &operator<<( ostream &,const Complex & );//语法错误 : 缺少“;”(在“&”的前面)//“ostream”: 不允许在数据声明中使用“friend”//语法错误: 标识符“ostream”
friend istream &operator>>( istream &, Complex & );
}

ostream &operator<<( ostream &output, const Complex & c)
{
output<<c.real<<"+"<<c.imaginary<<"i"<<endl;
return output;
}
istream &operator>>( istream &input, Complex & c)
{
input>>c.real;
input>>c.imaginary;
return input;
}
...全文
734 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
paschen 2018-04-18
  • 打赏
  • 举报
回复
ostream 改成 std::ostream 或者前面加上 using namespace std;

33,311

社区成员

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

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