c++thisthis-pointer

Can you explain the concept of the this pointer?


I need to understand this pointer concept, preferably with an example.

I am new to C++, so please use simple language, so that I can understand it better.


Solution

  • this is a pointer to an instance of its class and available to all non-static member functions.

    If you have declared a class, which has a private member foo and a method bar, foo is available to bar via this->foo but not to "outsiders" via instance->foo.