Overloading Unary Operators (C++)

Overloading Unary Operators (C++)

The unary operators are shown in the following table.

  1. ! (logical NOT)

  2. & (address-of)

  3. ~ (one's complement)

  4. * (pointer dereference)

  5. + (unary plus)

  6. - (unary negation)

  7. ++ (increment)

  8. -- (decrement)

  9. conversion operators

Of the operators shown in preceding table, the postfix increment and decrement operators (++ and ––) are treated separately in Increment and Decrement.

Conversion operators are also discussed in a separate topic; see Conversion Functions.

To declare a unary operator function as a nonstatic member, you must declare it in the form:

ret-type operatorop()

where ret-type is the return type and op is one of the operators listed in the preceding table.

To declare a unary operator function as a global function, you must declare it in the form:

ret-type operatoroparg)

where ret-type and op are as described for member operator functions and the arg is an argument of class type on which to operate.


There is no restriction on the return types of the unary operators. For example, it makes sense for logical NOT (!) to return an integral value, but this is not enforced.

Community Additions

© 2015 Microsoft