I have code that compiles without errors in Visual Studio 2010. But g ++ puts an error
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
Please tell me what the problem is with my code.
complex.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; }
Complex.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()); };
source share