Overloading prefix inc. & dec. operators

why do you need to return *this at the next code sample:

1
2
3
4
5
6
7
8
9
10
11
Digit& Digit::operator++()
{
    // If our number is already at 9, wrap around to 0
    if (m_nDigit == 9)
        m_nDigit = 0;
    // otherwise just increment to next number
    else
        ++m_nDigit;
 
    return *this;
}
That's how the operator is supposed to behave. You wouldn't be able to use it in an expression if didn't do that.
Topic archived. No new replies allowed.