已经使用转换构造函数了为什么还是不能实现double型数据和复数相加
#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;}
friend complex operator +(complex &c1,complex &c2);
void display();
private:
double real;
double image;
};
complex operator +(complex & c1,complex &c2)
{
return complex(c1.real+c2.real,c1.image+c2.image);
}
void complex::display()
{
if(image>0)
cout<<real<<"+"<<image<<"i"<<endl;
else
cout<<real<<image<<"i"<<endl;
}
int main()
{
complex t1(2,3),t2(2.4,5.7),t3,t4,t5;
t3=t1+t2;
t3.display();
t4=2.5+t1;
t4.display();
t5=t1+2.5;
t5.display();
return 0;
}