What is operator overloading, which operators cannot be overloaded, and what semantics should overloads preserve?
Show answer and explanation
Operator overloading defines how an existing operator acts when at least one operand has class or enumeration type. It cannot invent syntax or change precedence, associativity, or arity, and operators such as ::, ., .*, ?:, and sizeof cannot be overloaded. A good overload preserves the operator's conventional meaning and laws where practical—for example, implement addition without surprising mutation and keep equality consistent—because merely making an expression compile does not make its API intuitive.
Operator overloading defines how an existing operator acts when at least one operand has class or enumeration type. It cannot invent syntax or change precedence, associativity, or arity, and operators such as ::, ., .*, ?:, and sizeof cannot be overloaded. A good overload preserves the operator's conventional meaning and laws where practical—for example, implement addition without surprising mutation and keep equality consistent—because merely making an expression compile does not make its API intuitive.
Connect the conclusion directly to the type, lifetime, ownership, overload-resolution rule, or library contract present in the question. State implementation dependence or a violated precondition explicitly instead of merely guessing output.