I saw an example about implementing pre-increment and post-increment, which claims that overloading pre-increment is able to be defined as
T& T ::operator++()
and overloading post-increment can be defined and implemented in terms of pre-incremet as follows
const T T::operator++(int){
const T old(*this);
++(*this);
return old;
}
I have two questions:
1) what does “old” mean?
2) ++(*this) is assumed to use the pre-increment, and the original pre-increment definition does not have argument. However, it has *this here.
The method is a post increment. The current value (“old value”) is returned and then the value is incremented (“new value”).
*thisis not an argument. The parentheses are not necessary, they are there for readability.It’s equivalent to
++*this.