[求助]转换构造函数能实现这个功能么
我在VC++6.0编译系统下运行这个C++程序,显示在c3=c1+2.5这条语句有错误,但我已经定义转换构造函数了,2.5应该转为Complex(2.5),请大侠指点,不胜感激
#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;
};
void Complex::display()
{
cout<<real<<"i"<<image<<endl;
}
Complex operator + (Complex &c1,Complex &c2)
{
return Complex(c1.real+c2.real,c1.image+c2.image);
}
int main()
{
Complex c1(3,4),c2(4,8),c3;
c3=c1+2.5;
c3.display();
return 0;
}