Arithmetic operators
From Cppreference
Returns the result of specific arithmetic operation.
Operator name | Syntax | Overloadable | Prototype examples (for class T) | |
---|---|---|---|---|
Inside class definition | Outside class definition | |||
unary plus | +a | Yes | T& T::operator+() const; | T& operator+(const T &a); |
unary minus | -a | Yes | T& T::operator-() const; | T& operator-(const T &a); |
addition | a + b | Yes | T& T::operator+(const T2 &b) const; | T& operator+(const T &a, const T2 &b); |
subtraction | a - b | Yes | T& T::operator-(const T2 &b) const; | T& operator-(const T &a, const T2 &b); |
multiplication | a * b | Yes | T& T::operator*(const T2 &b) const; | T& operator*(const T &a, const T2 &b); |
division | a / b | Yes | T& T::operator/(const T2 &b) const; | T& operator/(const T &a, const T2 &b); |
modulo | a % b | Yes | T& T::operator%(const T2 &b) const; | T& operator%(const T &a, const T2 &b); |
bitwise NOT | ~a | Yes | T& T::operator~() const; | T& operator~(const T &a); |
bitwise AND | a & b | Yes | T& T::operator&(const T2 &b) const; | T& operator&(const T &a, const T2 &b); |
bitwise OR | a | b | Yes | T& T::operator|(const T2 &b) const; | T& operator|(const T &a, const T2 &b); |
bitwise XOR | a ^ b | Yes | T& T::operator^(const T2 &b) const; | T& operator^(const T &a, const T2 &b); |
bitwise left shift | a << b | Yes | T& T::operator<<(const T2 &b) const; | T& operator<<(const T &a, const T2 &b); |
bitwise right shift | a >> b | Yes | T& T::operator>>(const T2 &b) const; | T& operator>>(const T &a, const T2 &b); |
|
[edit] Explanation
All arithmetic operators compute the result of specific arithmetic operation and returns its result. The arguments are not modified.
[edit] See also
Common operators | ||||||
---|---|---|---|---|---|---|
assignment | increment decrement |
arithmetic | logical | comparison | member access |
other |
a = b a = rvalue |
++a --a |
+a -a |
!a a && b |
a == b a != b |
a[b] *a |
a(...) a, b |
Special operators | ||||||
static_cast converts one type to another compatible type |