Lecture 4 - Slide 39 : 40
Operator overloading
C++ supports comprehensive overloading of existing operators
The C++ Prog. Lang. (3. edition)
:
Page 261-...
The C++ Prog. Lang. (4. edition)
: Page 527ff.
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++ Prog. Lang. (3. edition)
:
Page 286 - ...
The C++ Prog. Lang. (4. edition)
: Page 549ff.