我的代码在 Visual Studio 2010 中编译时没有错误。但是 g++ 出错了
CComplex.cpp: In member function 'Complex Complex::operator+(Complex&)':
CComplex.cpp:22: error: no matching function for call to 'Complex::Complex(Complex)'
CComplex.cpp:15: note: candidates are: Complex::Complex(Complex&)
make: *** [CComplex.o] Error 1
请告诉我我的代码有什么问题。
复杂的.h
class Complex
{
public:
Complex();
Complex(double _Re, double _Im);
Complex(Complex& c);
Complex operator+(Complex& num);
inline double& fRe(void){return Re;}
inline double& fIm(void){return Im;}
protected:
double Re;
double Im;
}
复杂的.cpp
Complex::Complex(){
Re = 0.0;
Im = 0.0;
}
Complex::Complex(double re, double im){
Re = re;
Im = im;
}
Complex::Complex(Complex& complex){
*this = complex;
}
Complex Complex::operator+(Complex& num){
return Complex(Re + num.fRe(), Im + num.fIm());
};