1. Line 13 is the one I was referring to. It's almost a copy ctor, but not quote because of the const thing I mentioned before (it would be a copy ctor if 'z' was passed by const reference)
1.5. Also you don't need to write an assignment operator (line 23) either, for the same reason. The default assignment operator will work just fine for this class.
2. Yes @ your first question. No @ your second question. It's const correctness. Basically any member function that doesn't change the state of the object should be const.
See how your +, -, etc operators have that const keyword after them? That means they won't change any data members of the class. Since you get, etc functions don't change anything, they should also be const. Otherwise something like this would be a problem:
1 2 3
|
const complex foo = whatever;
double bar = foo.get_im(); // ERROR, 'foo' is const, so you can't call a nonconst function
|
EDIT: oh yeah... the PS:
I think it might be one of the keywords that were added as an alternative to using symbols that are hard to type on some keyboards.
IE:
and
became a keyword as an alternative to the & symbol
xor
became a keyword as an alternative to ^
and I guess
compl
became an alternative to ~
Honestly, I didn't know about compl myself until I saw this post