Increment/decrement operators
From Cppreference
Increment/decrement operators increments or decrements the value of the object.
Operator name | Syntax | Over​load​able | Prototype examples (for class T) | |
---|---|---|---|---|
Inside class definition | Outside class definition | |||
pre-increment | ++a | Yes | T& T::operator++(); | T& operator++(const T &a); |
pre-decrement | --a | Yes | T& T::operator--(); | T& operator--(const T &a); |
post-increment | a++ | Yes | T& T::operator++(int); | T& operator++(const T &a, int); |
post-decrement | a-- | Yes | T& T::operator--(int); | T& operator--(const T &a, int); |
|
[edit] Explanation
pre-increment and pre-decrement operators increments or decrements the value of the object and returns the resulting value.
post-increment and post-decrement operators increments or decrements the value of the object and returns the value of the object before the operation. Because a temporary copy of the object is made during the operation, for efficiency reasons it is better to employ pre-increment or pre-decrement operators in contexts where the returned value is not used.
[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 |