F
foolsmart2005
ComplexNum ComplexNum:
perator +(const ComplexNum& rhs) const //
- operation is the similar way
{
ComplexNum ans;
ans.real = real + rhs.real;
ans.imaginary = imaginary + rhs.imaginary;
return ans;
}
it works and my lecturer said it is correct but,
for += operation, my code is:
ComplexNum ComplexNum:
perator += (const ComplexNum& rhs) const
{
ComplexNum ans;
ans.real += rhs.real;
ans.imaginary += rhs.imaginary;
return ans;
}
here is lecturer's comment:
+= should be different. a += b means a = a + b
therefore *this object (i.e. a) should be updated with the answer.
Do anyone know how to write += operation?
- operation is the similar way
{
ComplexNum ans;
ans.real = real + rhs.real;
ans.imaginary = imaginary + rhs.imaginary;
return ans;
}
it works and my lecturer said it is correct but,
for += operation, my code is:
ComplexNum ComplexNum:
{
ComplexNum ans;
ans.real += rhs.real;
ans.imaginary += rhs.imaginary;
return ans;
}
here is lecturer's comment:
+= should be different. a += b means a = a + b
therefore *this object (i.e. a) should be updated with the answer.
Do anyone know how to write += operation?