Lecture overview -- Keyboard shortcut: 'u'  Previous page: Discussion - Encapsulation, Visibility and Access -- Keyboard shortcut: 'p'  Next page: Example: Operator overloading in class Point -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Lecture 3 - Page 35 : 36
Notes about C++
Abstraction Mechanisms, Part 1
Operator overloading

C++ supports comprehensive overloading of existing operators

  • The C++ Programming Language: Page 261 - ...
 

  • Restrictions on operator overloading

    • It is not possible to invent new operator symbols.

    • The associativity and precedence of the predefined rules of predefined operators apply

    • The following operators cannot be overloaded: :: (scope), . (member selection), .* (member selection through pointer), ?: (conditional, ternary), sizeof, typeid.

    • At least one operand must be of a user-defined type

    • If the left operand is of user-defined type, the operator may be defined as a member function

    • If the left operand is a predefined type, the operator must be a non-member function

For some operators, special rules and interpretations apply

  • The C++ Programming Language: Page 286 - ...