I always see solutions to some questions regarding classes, and they have (*this) , I don't understand when to use it and how to use it. Does it just mean that we're referring to something? Please help me out. (an explaination with an example would be helpful)


this is a special pointer that points to the active object. For example:

#include <iostream>
#include <string>
using namespace std;

class WhoAmI
    string name;
    WhoAmI( const string& name ): name( name ) { }
    void print( const WhoAmI& other )
      cout << "I am " << this->name << endl;
      if (this == &other)
        cout << "I am beside myself.\n";
        cout << "I am with " << other.name << endl;

int main()
  WhoAmI george( "George" );
  WhoAmI alannah( "Alannah" );

  george.print( george );
  alannah.print( george );

  return 0;

Hope this helps.