类型转换函数应用调试问题
#include<iostream.h>class complex
{public:
complex(){real=0;image=0;}
complex(double r){real=r;image=0;}
complex(double r,double i){real=r;image=i;}
void display();
friend complex operator+(complex c1,complex c2);
double real;
double image;
};
complex operator+(complex c1,complex c2)
{return(c1.real +c2.real ,c1.image +c2.image );}
void complex::display ()
{cout<<"("<<real<<"+"<<image<<"i)"<<endl;}
int main()
{ complex c1(3,4),c2(5,-10),c3;
c3=c1+2.5;
cout<<c3<<endl;
return 0;
}
哪位兄弟看下,我调试的时候出现
------------------Configuration: Textdd - Win32 Debug--------------------
Compiling...
Textdd.cpp
c:\documents and settings\administrator\桌面\ggg\textdd.cpp(21) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class complex' (or there is no acceptable conversion)
Error executing cl.exe.
Textdd.obj - 1 error(s), 0 warning(s)
不知道出现了什么问题,哪位兄弟帮忙看下了,谢谢!