Rules for overloading an operator
This summarizes the most significant points you need to know in order to do operator function overloading.
- The only operators you may overload are the ones from the C++ list and not all of those are available. You cannot arbitrarily choose a new symbol (such as @) and attempt to "overload it.
- Start by declaring a function in the normal function fashion, but for the function name use the expression:
Operator op
Where op is the operator to be overloaded. You may leave one or more spaces before op.
- The pre-defined precedence rules cannot be altered. i.e. you cannot, for instance, make binary '+' have higher precedence than binary '*'. In addition, you cannot alter the associativity of the operators.