October 2004
Intermediate to advanced
624 pages
16h 2m
English
The built-in prefix and postfix increment and decrement operators are great shorthand. Rather than writing
x = x + 1;
we can simply write
++x;
or
x++;
Of greater significance, especially since the advent of the STL, is that these operators can be overloaded for class types. The prefix increment and decrement operators are defined for classes by the following functions:
class X
{
. . .
X &operator ++(); // pre-increment
X &operator —(); // pre-decrement
X operator ++(int); // post-increment
X operator —(int); // post-decrement
. . .
Although there's nothing forcing you to do so, the intent is that the return types of the prefix and postfix forms are as shown above, that is, that the prefix forms return a non-const ...
Read now
Unlock full access