Restriction on Operator Overloading

Cannot change:
1. Precedence of operator (order of evaluation)
  • Use parentheses to force an order of operators.
2. Associativity (left-to-right or right-to-left)
3. Number of operands
  • e.g., & is unary, can only act on one operand.
4. How operators act on built-in data types (i.e., cannot change integer addition).
  • Cannot create new operators.
  • Operators must be overloaded explicitly.
5. Overloading + and = does not overload +=

Post a Comment

Previous Post Next Post