Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Operators in C and C++
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Other=== {| class="wikitable" style="width:100%" ! colspan="2" rowspan="2" | Operation ! rowspan="2" | Syntax ! rowspan="2" | Can overload ! rowspan="2" | In C ! colspan="2" | C++ prototype |- ! in class K ! outside class |- | {{rh}} colspan="2" | [[function (programming)|Function]] call | align="center" | <code>a'''('''a1, a2''')'''</code> | {{yes}} | {{yes}} | {{cpp|1=R K::operator ()(S a, T b, ...);}}<!--'operator' shows as blue even though other prototypes shows it as green; seems to be a bug in the cpp template; unknown how to workaround.--> | {{n/a}} |- | {{rh}} colspan="2" | [[comma operator|Comma]] | style="text-align:center;" | <code>a''',''' b</code> || {{yes}} || {{yes}} | {{cpp|1=R K::operator ,(S b);}} | {{cpp|1=R operator ,(K a, S b);}} |- | {{rh}} colspan="2" | [[?:|Ternary conditional]] | style="text-align:center;" | <code>a '''?''' b ''':''' c</code> || {{no}} || {{yes}} | colspan="2" {{n/a}} |- | {{rh}} colspan="2" | [[Scope resolution operator#C++|Scope resolution]] | style="text-align:center;" | <code>a'''::'''b</code><ref name="scopal" group="lower-alpha" /> || {{no}} || {{no}} | colspan="2" {{n/a}} |- | {{rh}} colspan="2" | User-defined literals<ref name="ud-literal" group="lower-alpha" /><ref name="sinceCXX11" group="lower-alpha" /> | style="text-align: center;" | <code><nowiki>"a"_b</nowiki></code> || {{yes}} || {{no}} | {{n/a}} | {{cpp|1=R operator "" _b(T a)}} |- | {{rh}} colspan="2" | [[Sizeof]] | style="text-align:center;" | <code>'''sizeof''' a</code><ref name="sizeof" group="lower-alpha" /><br /><code>'''sizeof''' (R)</code> || {{no}} || {{yes}} | colspan="2" {{n/a}} |- | {{rh}} colspan="2" | Size of [[variadic template|parameter pack]]<ref name="sinceCXX11" group="lower-alpha" /> | style="text-align:center;" | <code>'''sizeof...'''(Args)</code> || {{no}} || {{no}} | colspan="2" {{n/a}} |- | {{rh}} colspan="2" | Alignof<ref name="sinceCXX11" group="lower-alpha" /> | style="text-align:center;" | <code>'''alignof'''(R)</code> <br> or <code>'''_Alignof'''(R)</code><ref name="alignof" group="lower-alpha"/> || {{no}} || {{yes}} | colspan="2" {{n/a}} |- | {{rh}} colspan="2" | [[Decltype]]<ref name="sinceCXX11" group="lower-alpha" /> | style="text-align:center;" | <code>'''decltype''' (a)</code><br/><code>'''decltype''' (R)</code> || {{no}} || {{no}} | colspan="2" {{n/a}} |- | {{rh}} colspan="2" | Type identification | style="text-align:center;" | <code>'''typeid'''(a)</code><br><code>'''typeid'''(R)</code> || {{no}} || {{no}} | colspan="2" {{n/a}} |- | {{rh}} colspan="2" | [[type conversion|Conversion]]<br>{{small|(C-style cast)}} | style="text-align:center;" | <code>(R)a</code> || {{yes}} || {{yes}} | {{cpp|1=K::operator R();}}<ref>{{cite web|url=https://en.cppreference.com/w/cpp/language/cast_operator|title=user-defined conversion|access-date=5 April 2020}}</ref> | {{n/a}} |- | {{rh}} colspan="2" | [[type conversion|Conversion]]{{efn|Behaves like const_cast/static_cast/reinterpret_cast. In the last two cases, the <code>auto</code> specifier is replaced with the type of the invented variable x declared with <code>auto x(a);</code> (which is never interpreted as a function declaration) or <code>auto x{a};</code>, respectively.}}<ref>[https://en.cppreference.com/w/cpp/language/explicit_cast Explicit type conversion] in C++</ref> | style="text-align:center;" | <code>R(a)</code><br><code>R{a}</code><ref name="sinceCXX11" group="lower-alpha" /><br><code>auto(a)</code><ref name="sinceCXX23" group="lower-alpha" /><br><code>auto{a}</code><ref name="sinceCXX23" group="lower-alpha" /> || {{no}} || {{no}} | {{rh}} colspan="2" {{n/a}} |- | {{rh}} colspan="2" | [[static_cast]] conversion{{efn|For user-defined conversions, the return type implicitly and necessarily matches the operator name unless the type is inferred (e.g. {{cpp|1=operator auto()}}, {{cpp|1=operator decltype(auto)()}} etc.).}} | style="text-align:center;" | <code>'''static_cast'''<R>(a)</code> || {{yes}} || {{no}} | {{cpp|1=K::operator R();}}<br>{{cpp|1=explicit K::operator R();}}<ref name="sinceCXX11" group="lower-alpha" /> | {{n/a}} |- | {{rh}} colspan="2" | [[dynamic cast]] conversion | style="text-align:center;" | <code>'''dynamic_cast'''<R>(a)</code> || {{no}} || {{no}} | colspan="2" {{n/a}} |- | {{rh}} colspan="2" | [[const_cast]] conversion | style="text-align:center;" | <code>'''const_cast'''<R>(a)</code> || {{no}} || {{no}} | colspan="2" {{n/a}} |- | {{rh}} colspan="2" | [[reinterpret_cast]] conversion | style="text-align:center;" | <code>'''reinterpret_cast'''<R>(a)</code> || {{no}} || {{no}} | colspan="2" {{n/a}} |- | {{rh}} colspan="2" | [[new (c++)|Allocate storage]] | style="text-align:center;" | <code>'''new''' R</code><ref name="infer" group="lower-alpha"/> || {{yes}} || {{no}} | {{cpp|1=void* K::operator new(size_t x);}} | {{cpp|1=void* operator new(size_t x);}} |- | {{rh}} colspan="2" | Allocate array | style="text-align:center;" | <code>'''new''' R'''['''n''']'''</code><ref name="infer2" group="lower-alpha"/> || {{yes}} || {{no}} | {{cpp|1=void* K::operator new[](size_t a);}} | {{cpp|1=void* operator new[](size_t a);}} |- | {{rh}} colspan="2" | [[operator delete|Deallocate storage]] | style="text-align:center;" | <code>'''delete''' a</code> || {{yes}} || {{no}} | {{cpp|1=void K::operator delete(void* a);}} | {{cpp|1=void operator delete(void* a);}} |- | {{rh}} colspan="2" | Deallocate array | style="text-align:center;" | <code>'''delete[]''' a</code> || {{yes}} || {{no}} | {{cpp|1=void K::operator delete[](void* a);}} | {{cpp|1=void operator delete[](void* a);}} |- | {{rh}} colspan="2" | Exception check<ref name="sinceCXX11" group="lower-alpha" /> | style="text-align:center;" | <code>'''noexcept'''(a)</code> || {{no}} || {{no}} | colspan="2" {{n/a}} |}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)