Overloaded operators
Earlier we said that function names should not contain punctuation. That is not strictly true because, if you are writing an operator, you only use punctuation in the function name. An operator is used in an expression acting on one or more operands. A unary operator has one operand, a binary operator has two operands, and an operator returns the result of the operation. Clearly this describes a function: a return type, a name, and one or more parameters.
C++ provides the keyword operator
to indicate that the function is not used with the function call syntax, but instead is called using the syntax associated with the operator (usually, a unary operator the first parameter is on the right of the operator, and for a binary operator the first parameter is on the left and the second is on the right, but there are exceptions to this).
In general, you will provide the operators as part of a custom type (so the operators act upon variables of that type) but in some cases, you...