请大家帮忙改下错? 本帖最后由 VisualEleven 于 2012-10-19 20:59:38 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Complex类没有&成员函数,Complex&a怎么用? "Complex&a,&b" -> Complex &a,&b friend Complex operator+(Complex&a,&b);第一次看到函数参数这样写,难道不应该写成friend Complex operator+(Complex &a, Complex& b); ///////////////////////////////////////////////////////////////#include<iostream.h>//using namespace std;class Complex{double real;double imag;public: Complex (double r=0.0,double i=0.0); void print();// friend Complex operator+ (Complex a,Complex b); friend Complex operator- (Complex a,Complex b); friend Complex operator* (Complex a,Complex b); friend Complex operator/ (Complex a,Complex b);}; Complex::Complex(double r,double i){ real=r; imag=i;}Complex operator+ (Complex a,Complex b){ return Complex(a.real+b.real,a.imag+b.imag);}Complex operator- (Complex a,Complex b){ return Complex(a.real-b.real,a.imag-b.imag);}Complex operator* (Complex a,Complex b){ return Complex(a.real*b.real,a.imag*b.imag);}Complex operator/ (Complex a,Complex b){ Complex temp; double t; t=1/(b.real*b.real+b.imag*b.imag); temp.real=(a.real*a.real+a.imag*b.imag)*t; temp.imag=(b.real*a.imag-a.real*b.imag)*t; return temp;}void Complex::print(){ cout<<real; if(imag>0) cout<<"+"; if(imag!=0) cout<<'i'<< imag << endl;}int main(){ Complex A1(2.3,4.6),A2(3.6,2.8),A3,A4,A5,A6; A3=A1+A2; A4=A1-A2; A5=A1*A2; A6=A1/A6; A1.print(); A2.print(); A3.print(); A4.print(); A5.print(); A6.print(); return 0;}注意:#include<iostream.h>//using namespace std; XP注册表修改KeepAliveTime不起作用 线程注入另一个进程之后,它自身的线程会不会被主进程操控? 图像 最小二乘法直线拟合问题 新手学C++!帅哥美女来带带我吧 vista下如何写注册表把程序加入防火墙exception?搞不定就得丢饭碗了,救小弟一命!!! 一个带数据库的小程序,编译之后是什么情况? 编程中遇到的个问题请教。 如何实现WIN2000“服务”的停止和启动??? 同一进程内 线程数据共享问题? 请问大家,那里有介绍属性页、对话框和各种控件使用(比较详细)的资料下载? 用icmp实现traceroute功能 到最后一跳接收超时是什么问题? 读序列化对象小问题
第一次看到函数参数这样写,难道不应该写成
friend Complex operator+(Complex &a, Complex& b);
///////////////////////////////////////////////////////////////
#include<iostream.h>//using namespace std;class Complex
{
double real;
double imag;
public:
Complex (double r=0.0,double i=0.0);
void print();
//
friend Complex operator+ (Complex a,Complex b);
friend Complex operator- (Complex a,Complex b);
friend Complex operator* (Complex a,Complex b);
friend Complex operator/ (Complex a,Complex b);
};
Complex::Complex(double r,double i)
{
real=r;
imag=i;
}Complex operator+ (Complex a,Complex b)
{
return Complex(a.real+b.real,a.imag+b.imag);
}Complex operator- (Complex a,Complex b)
{
return Complex(a.real-b.real,a.imag-b.imag);
}Complex operator* (Complex a,Complex b)
{
return Complex(a.real*b.real,a.imag*b.imag);
}Complex operator/ (Complex a,Complex b)
{
Complex temp;
double t;
t=1/(b.real*b.real+b.imag*b.imag);
temp.real=(a.real*a.real+a.imag*b.imag)*t;
temp.imag=(b.real*a.imag-a.real*b.imag)*t;
return temp;
}void Complex::print()
{
cout<<real;
if(imag>0)
cout<<"+";
if(imag!=0)
cout<<'i'<< imag << endl;
}int main()
{
Complex A1(2.3,4.6),A2(3.6,2.8),A3,A4,A5,A6;
A3=A1+A2;
A4=A1-A2;
A5=A1*A2;
A6=A1/A6;
A1.print();
A2.print();
A3.print();
A4.print();
A5.print();
A6.print(); return 0;
}
注意:
#include<iostream.h>
//using namespace std;