logo

C++ - Operators

*

  • int* p: p is a pointer to an int
  • *p: dereference operator, "use the value a pointer points to"

&

  • int& r: r is an alias of some int
  • &r: address-of operator, "get the address of a variable"

&&

Indicates the parameter is an rvalue reference. Unlike an ordinary reference, it only binds to objects that are no longer needed, e.g. temporaries, or using std::move().

::

scope resolution operator (::) which is used to define a method outside of a class and to access a global variable within from the scope where a local variable also exists with the same name.

Leading ::

#define BOOST_THROW_EXCEPTION(x) ::boost::throw_exception(x)

Without the leading double-colon, C++ will first check if there is a namespace of that name within the current 'active' namespace. If there isn't then it will check for a namespace of the name at the top level.

With the leading double-colon, C++ will skip the first check and only look for a top-level namespace.

Spaceship operator <=>

auto X::operator<=>(const Y&) const = default;

Compiler will generate 6 comparison operators to compare X with Y