] > The Variable ‘this’

8.1 The Variable ‘this’

#include <iostream> 
using namespace std; 
 
class Ths{ 
  int value; 
public
  Ths(int value){ 
     (this).value = value; 
  } 
  void set(int value){ 
     (this).value = value; 
  } 
  int get(){ 
    int value = (this).value; 
     (this).set( 0 ); 
     return value; 
  } 
}
 
int main() { 
  Ths obj(0); 
 
  obj.set(11); 
  cout << obj.get() 
       << ”  ” 
       << obj.get() 
       << endl; 
  return 0; 
}
#include <iostream> 
using namespace std; 
 
class Ths{ 
     int value; 
   public
     Ths(int v){ 
        value = v; 
     } 
     void set(int v){ 
        value = v; 
     } 
     int get(){ 
        int v = value; 
        set( 0 ); 
        return v; 
     } 
}
 
int main() { 
  Ths obj(0); 
 
  obj.set(11); 
  cout << obj.get() 
       << ”  ” 
       << obj.get() 
       << endl; 
  return 0; 
}

[ths.cpp] [inside.cpp]