Unary Operators

Unary operators have only one operand. They include increment and decrement operators, negation operators, logical and bitwise negation, positive and negative sign operators, cast, address, and dereference operators, and operators new, delete, and sizeof. All these operators (with the exception of sizeof) can be overloaded.

Of course, not every operator can have its own special meaning for every class. In Chapter 10, I overloaded the positive sign operator for class Complex as an output operator, and this design is confusing. This is why overloading of unary operators is not very popular. However, there are some situations where these operators can contribute to intuitive understanding of the client code. In this section, I will ...

Get Core C++ A Software Engineering Approach 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.