The *this pointer returning a reference

I think the following member functions operator++ and operator-- code return a reference of type Digit. I think the *this pointer returns the member functions current object. So I guess the Object of type Digit private data member m_nDigit is incremented or decremented and being returned as the data member of returned object. If an object is being returned I don't understand how a reference to object is returned. Could you explain how this computes?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Digit 
{ 
  private:     
          int m_nDigit; 
   public:     
         Digit(int nDigit=0){m_nDigit = nDigit;}       
         Digit& operator++();     
         Digit& operator--();       
         int GetDigit() const { return m_nDigit; } 
};   
   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; 
     }   

     Digit& Digit::operator--() 
     {    
  // If our number is already at 0, wrap around to 9     
     if (m_nDigit == 0)         
         m_nDigit = 9;     
  // otherwise just decrement to next number     
      else       
          --m_nDigit;       
        return *this; 
}
Last edited on
Use code tags.
Topic archived. No new replies allowed.