我的源文件如下:
#include <iostream.h>
class Complex
{
public:
Complex(){real=0;imag=0;}
Complex(double r){real=r;imag=0;}
Complex(double r,double i){real=r;imag=i;}
Complex operator + (Complex c2);/*改为Complex operator + (Complex &c2)就出现编译错误*/
void display();
private:
double real;
double imag;
};
Complex Complex::operator + (Complex c2)/*也改为Complex operator + (Complex &c2)*/
{return Complex(real+c2.real,imag+c2.imag);}
void Complex::display()
{cout<<"("<<real<<","<<imag<<"i)"<<endl;}
int main()
{
Complex c1(3,4),c2(5,-10),c3;
c3=c1+2.5;
c3.display();
return 0;
}
我不明白为什么会这样,我用的是VC6.0编译器,有哪位高人帮我解答一下,万分感谢。