Comparison operators

From Cppreference

Jump to: navigation, search

Accesses a member of an object.

Operator name Syntax Over​load​able Prototype examples (for class T)
Inside class definition Outside class definition
array subscript a[b] Yes R T::operator[](const T2 &b); N/A
indirection (variable pointed to by a) *a Yes R& T::operator*(); R& operator(T &a);
address of &a Yes R* T::operator&(); R* operator&(T &a);
member of object a.b No N/A N/A
member of pointer a->b Yes R* T::operator->() N/A
pointer to member of object a.*b No N/A N/A
member of pointer a->b Yes R* T::operator->*(R) R* T::operator->*(T, R)
Notes
  • The return type R can essentially be any type. However, some some operators are expected to return specific types,
    e.g. indirection operator is expected to return reference type. If other types are returned, the operator operation
    becomes unintuitive and thus defeats the purpose of the operators.

[edit] Explanation

array subscript operator provides access to the elements in the internal array

indirection, member of pointer and pointer to member of pointer operators provide provide pointer semantics for any object.

member of pointer and pointer to member of pointer operators return a pointer to the actual object which will be used for member access.

[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)