I have been given the following lines of code
class Complex{
private:
double re, im;
public:
Complex (double Re=0, double Im=0): re(Re), im(Im) {}
double real() { return re; }
double imag() {return im; }
};
My question pertains to the constructor (of whose purpose I'm still not quite sure)
I'm used to writing the constructor as:
Complex (double Re = 0, double Im = 0): {Re = re, Im = im;}
rather than:
Complex (double Re=0, double Im=0): re(Re), im(Im) {}
Are the two lines of code equivalent, and specifically what does re(Re)
and im(Im)
do?