As in your previous question, your interface is still awkward. That is, if there's an add
method, I fully expect that calling a.add(b)
will mean that a results in a plus b. So in particular, the state of a
will be changed.
For example, I would write add
as:
ComplexNumber operator+=(const ComplexNumber& b) {
real += b.real;
imaginary += b.imaginary;
return *this;
}
Similarly for the other three functions.
A user of your class will also find void printNumber(char mathOperator)
weird. Indeed, why as a user of the class do I need to worry about such details meaning the parameter? The user will just want to get his/her complex number printed and not be forced to worry about such details. So such a function might make sense as a private workhorse (but do make it const
and read more about const
- it's good for you) that operator<<
can call, as explained in another answer.