Skip to Content
Navigating C++ and Object-Oriented Design
book

Navigating C++ and Object-Oriented Design

by Paul Anderson, Gail Anderson
October 1997
Intermediate to advanced
800 pages
20h 48m
English
Pearson
Content preview from Navigating C++ and Object-Oriented Design

6.5. Overloadable Operators

The C++ compiler parses expressions into operands and operators, as shown in Table 6.9.

With the exception of the ternary conditional operator (?:), all C++ operators work with either one operand (unary) or two operands (binary).

Table 6.9. Operator formats in C++
Expression Format Operator Type Examples
left_operand operator right_operand Binary a + b, a > b
left_operand operator Unary (Postfix) a++, a--, a->
operator right_operand Unary (Prefix) ++a, --a, *a
operand1 ? operand2 : operand3 Ternary a > b ? a : b

Table 6.10 lists the unary operators that you may overload.

Table 6.10. Unary operator overloading
Operator Examples Operator Examples
+ +a ~ ~a
- -a ! !a
* *a ++ a++, ++a
& &a -- a--, --a
-> a->   

Table 6.11 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Exploring C++20: The Programmer's Introduction to C++

Exploring C++20: The Programmer's Introduction to C++

Ray Lischner

Publisher Resources

ISBN: 0135327482Purchase book