友元函数的重载问题

ewfc12ewrew ewfc12ewrew 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#include<iostream>
using namespace std;

class complex
{
private:
double real;
double image;
public:
complex(double r=0,double i=0):real(r),image(i)
{}
friend complex operator+(complex &c1,complex &c2);

void display()
{
cout<<"("<<real<<","<<image<<")"<<endl;
}
};
complex operator+(complex &c1,complex &c2)
{

complex A(c1.real+c2.real,c2.image+c2.image);
return A;
}

int
main()
{
complex c1(2.4,3.1),c2(4.4,5.6),c3;
c3=c1+c2;
c3.display();
return 0;
}
//程序编译老出现documents and settings\administrator\桌面\a109.cpp(12) : fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 1786)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
不知我的程序哪里错了???
...全文
评论 6
收藏 已收藏
分享
返回顶部
ewfc12ewrew
C++ 语言 65,214 成员 250,514 内容