1struct X
2{
3 // prefix increment
4 X& operator++()
5 {
6 // actual increment takes place here
7 return *this; // return new value by reference
8 }
9
10 // postfix increment
11 X operator++(int)
12 {
13 X old = *this; // copy old value
14 operator++(); // prefix increment
15 return old; // return old value
16 }
17
18 // prefix decrement
19 X& operator--()
20 {
21 // actual decrement takes place here
22 return *this; // return new value by reference
23 }
24
25 // postfix decrement
26 X operator--(int)
27 {
28 X old = *this; // copy old value
29 operator--(); // prefix decrement
30 return old; // return old value
31 }
32};
1class Point
2{
3public:
4 Point& operator++() { ... } // prefix
5 Point operator++(int) { ... } // postfix
6 friend Point& operator++(Point &p); // friend prefix
7 friend Point operator++(Point &p, int); // friend postfix
8 // in Microsoft Docs written "friend Point& operator++(Point &p, int);"
9};
10