VS2010C++为什么会出现这么多错误 程序如下。友元重载运算符。

#include<iostream>usingnamespacestd;classcomplex{public:complex(){real=imag=0;}comple... #include <iostream>

using namespace std;
class complex
{public:
complex()
{real=imag=0;}
complex(double i,double r)
{real=i;
imag=r;}
friend complex operate +(const complex&c1,const complex&c2);
friend complex operate -(const complex&c1,const complex&c2);
friend complex operate *(const complex&c1,const complex&c2);
friend complex operate /(const complex&c1,const complex&c2);
void print(const complex&c)
{if(c.imag<0)
cout<<c.real<<c.imag<<'i'<<endl;
else
cout<<c.real<<'+'<<c.imag<<'i'<<endl;}
private:
double real,imag;
};
complex operate +(const complex&c1,const complex&c2)
{return complex(c1.real+c2.real,c1.imag+c2.imag);}
complex operate -(const complex&c1,const complex&c2)
{return complex(c1.real-c2.real,c1.imag-c2.imag);}
complex operate *(const complex&c1,const complex&c2)
{return complex(c1.real*c2.real-c1.imag*c2.imag,c1.real*c2.imag+c1.imag*c2.real)
complex operate /(const complex&c1,const complex&c2)
{return complex(c1.real*c2.real+c1.imag*c2.imag/c2.real*c2.real+c2.imag*c2.imag,c1.imag*c2.real-c1.real*c2.imag/c2.real*c2.real+c2.imag*c2.imag);}

int main()
{complex c1(2.0,3.0),c2(4.0,-2.0),c3;
c3=c1+c2;
cout<<"\nc1+c2=";
print(c3);
c3=c1-c2;
cout<<"\nc1-c2";
print(c3);
c3=c1*c2;
cout<<"\nc1*c2";
print(c3);
c3=c1/c2;
cout<<"\nc1/c2";
print(c3);
c3=(c1+c2)*(c1-c2)*c2/c1;
cout<<"\n(c1+c2)*(c1-c2)*c2/c1=";
print(c3);
cout<<endl;
return 0;
}

比如:C2433: “operate”: 不允许在数据声明中使用“friend”

求解谢谢谢谢谢!!!!
展开
 我来答
  • 你的回答被采纳后将获得:
  • 系统奖励15(财富值+成长值)+难题奖励30(财富值+成长值)
笃侠6A
2015-05-20 · TA获得超过3734个赞
知道大有可为答主
回答量:3205
采纳率:75%
帮助的人:3267万
展开全部
operator 写成 operate 了吧
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式