B - Operators

Warning

🚧 Page Under Construction! 🏗️

This page is a high level overview of C++ operators and other symbols and what they do.

  • ✅ - Fully overloadable
  • ☑️ - Overloadable with constraints
  • ⚠️ - Overloadable but not recommended
  • ❌ - Not overloadable

Basic Operators

OperatorExampleDescriptionOverloadable
++exprArithmetic posigation
+expr + exprArithmetic addition
++++exprPrefix increment
++expr++Postfix increment
+=var += exprArithmetic addition and assignment
--exprArithmetic negation
-expr - exprArithmetic subtraction
----exprPrefix decrement
--expr--Postfix decrement
-=var -= exprArithmetic subtraction and assignment
**exprPointer dereference☑️
*expr * exprArithmetic multiplication
*=var *= exprArithmetic multiplication and assignment
/expr / exprArithmetic division
/=var /= exprArithmetic division and assignment
%expr % exprArithmetic remainder
%=var %= exprArithmetic remainder and assignment
~~exprBitwise Complement
&&exprAddress of
&type ident&, type ident const&Reference type
&expr & exprBitwise AND
&=var &= exprBitwise AND and assignment
&&expr && exprLogical AND☑️
|expr | exprBitwise OR
|=var |= exprBitwise OR and assignment
||expr || exprLogical OR☑️
^expr ^ exprBitwise XOR
^=var ^= exprBitwise XOR and assignment
<<expr << exprBitwise left shift
<<=var <<= exprBitwise left shift and assignment
>>expr >> exprBitwise right shift
>>=var >>= exprBitwise right shift and assignment
!!exprLogical NOT
==expr == exprEquality comparison
!=expr != exprInequality comparison
<expr < exprLess than
<=expr <= exprLess than or equal
>expr > exprGreater than
>=expr >= exprGreater than or equal
<=>expr <=> exprThree way comparison
[]expr[expr, expr, ..]Subscript / array indexing (multi-argument since C++23)
()expr(expr, expr, ..)Function object invocation
,expr, exprComma sequencing⚠️
=var = expr, ident = exprAssignment / Binding☑️
?:expr ? expr : exprTernary expression
::ident::ident, ident::varNamespace lookup
...typename types..., type T..., T... argsParameter type and value packs
.expr.identMember access
.*expr.*identMember access to pointer members
->expr->identMember access through a pointer☑️
->*expr->*identMember access through a pointer to pointer members☑️
""literal_suffix-identUser defined literal☑️

Memory Operators

OperatorExampleDescription
newnew type (init-list)Allocate a heap memory object constructed with parameters in init-list
new []new type[size] {init-list}Allocate a heap memory block initialized with elements in init-list
deletedelete exprDelete heap memory object
delete []delete [] exprDeletes heap memory block

Type Casting Operators

OperatorExampleDescription
static_caststatic_cast<T>(expr)Casts expr to type T
dynamic_castdynamic_cast<T>(expr)Casts pointers and references to classes up, down and sideways through inheritance hierarchy
reinterpret_castreinterpret_cast<T>(expr)Casts expr to type T by reinterpreting underlying bits of expr
const_castconst_cast<T>(expr)Can cast to or away const when type of expr and T are similar types
C-cast(type)exprLegacy type cast from C, uses a combination of above casts

Other Operators

OperatorExampleDescription
sizeofsizeof(expr), sizeof(type)Obtains the size in bytes of a type or expression
sizeof...sizeof...(pack-expr), sizeof(pack-type)Obtains the number of elements of a parameter pack
typeidtypeid(expr), typeid(type)Obtains compiler representation of a type
noexceptnoexcept(expr)Checks if an expression will throw an exception
alignofalignof(typeid)Obtains the alignment required by a type