Files
cppdraft_translate/cppdraft/over/unary.md
2025-10-25 03:02:53 +03:00

50 lines
2.1 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[over.unary]
# 12 Overloading [[over]](./#over)
## 12.4 Overloaded operators [[over.oper]](over.oper#over.unary)
### 12.4.2 Unary operators [over.unary]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3491)
A [*prefix unary operator function*](#def:operator_function,prefix_unary "12.4.2Unary operators[over.unary]") is a function named operator@ for a prefix [*unary-operator*](expr.unary.general#nt:unary-operator "7.6.2.1General[expr.unary.general]") @ ([[expr.unary.op]](expr.unary.op "7.6.2.2Unary operators"))
that is either
a non-static member function ([[class.mfct]](class.mfct "11.4.2Member functions")) with no non-object parameters or
a non-member function with one parameter[.](#1.sentence-1)
For a [*unary-expression*](expr.unary.general#nt:unary-expression "7.6.2.1General[expr.unary.general]") of the form @ [*cast-expression*](expr.cast#nt:cast-expression "7.6.3Explicit type conversion (cast notation)[expr.cast]"),
the operator function is selected by overload resolution ([[over.match.oper]](over.match.oper "12.2.2.3Operators in expressions"))[.](#1.sentence-2)
If a member function is selected,
the expression is interpreted as
[*cast-expression*](expr.cast#nt:cast-expression "7.6.3Explicit type conversion (cast notation)[expr.cast]") . operator @ ()
Otherwise, if a non-member function is selected,
the expression is interpreted as
operator @ ( [*cast-expression*](expr.cast#nt:cast-expression "7.6.3Explicit type conversion (cast notation)[expr.cast]") )
[*Note [1](#note-1)*:
The operators ++ and -- ([[expr.pre.incr]](expr.pre.incr "7.6.2.3Increment and decrement"))
are described in [[over.inc]](over.inc "12.4.7Increment and decrement")[.](#1.sentence-3)
— *end note*]
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3517)
[*Note [2](#note-2)*:
The unary and binary forms of the same operator have the same name[.](#2.sentence-1)
Consequently, a unary operator can hide a binary
operator from an enclosing scope, and vice versa[.](#2.sentence-2)
— *end note*]