6.6. Operator Functions

Class designers must make correct decisions when overloading operators for class objects. Otherwise, expressions may be ambiguous, generate undesired conversions, or produce compilation errors. This section covers general schemes for operator overloading and gives you guidelines for creating consistent class designs.

How does operator overloading work with objects? Expressions with unary or binary operands map to specialized function calls. Table 6.12 lists the formats.

A horizontal line in Table 6.12 separates two format groups. In the first group, # is any C++ operator except =, [], (), ->, and postfix ++ and -- (which appear in the second group). In both groups, the compiler translates expressions with C++ operators ...

Get Navigating C++ and Object-Oriented Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.