Other operators

From Cppreference

Jump to: navigation, search
Operator name Syntax Over​load​able Prototype examples (for class T)
Inside class definition Outside class definition
function call a(a1, a2) Yes R T::operator()(Arg1 &a1, Arg2 &a2, ... ...); N/A
comma a, b Yes T2& T::operator,(T2 &b); T2& operator,(const T &a, T2 &b);
conversion (type) a Yes operator type() N/A
ternary conditional a ? b : c No N/A N/A

[edit] Explanation

function call operator provides function semantics for any object.

conversion operator converts given type to another type. The name of the operator must be the same as the type intended to be returned.

ternary conditional operator checks the boolean value of the first expression and replaces entire operator clause with the second or the third expression depending on the resulting value. For example, {{{1}}} is equivalent to {{{1}}}

[edit] See also

Operator precedence

Common operators
assignment increment
decrement
arithmetic logical comparison member
access
other
a = b

a = rvalue
a += b
a -= b
a *= b
a /= b
a %= b
a &= b
a |= b
a ^= b
a <<= b
a >>= b

++a

--a
a++
a--

+a

-a
a + b
a - b
a * b
a / b
a % b
~a
a & b
a | b
a ^ b
a << b
a >> b

!a

a && b
a || b

a == b

a != b
a < b
a > b
a <= b
a >= b

a[b]

*a
&a
a->b
a.b
a->*b
a.*b

a(...)

a, b
(type) a
? :

Special operators

static_cast converts one type to another compatible type
dynamic_cast converts virtual base class to derived class
const_cast converts type to compatible type with different cv qualifiers
reinterpret_cast converts type to incompatible type
new allocates memory
delete deallocates memory
sizeof queries the size of a type
sizeof... queries the size of a parameter pack (C++11 feature)
typeid queries the type information of a type
noexcept checks if an expression can throw an exception (C++11 feature)
alignof queries alignment requirements of a type (C++11 feature)