为什么通不过编译?

wangzeba wangzeba 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
为什么通不过编译?
#include<iostream.h>
class complex
{
private:
int real;
int imag;
public:
complex(int r=0,int i=0)
{
real=r;
imag=i;
}
friend complex operator +(complex &,complex &);
void show()
{
cout<<real<<"+"<<imag<<"i";
}
};

friend complex operator + (complex &a,complex &b)
{
int r1=a.real+b.real;
int i1=a.imag+b.imag;
return complex(r1,i1);
}

void main()
{
complex x(2,3),y(4,5),z;
z=x+y;
z.show();
}

...全文
评论 6
收藏 已收藏
分享
返回顶部
wangzeba
C++ 语言 65,213 成员 250,513 内容