this Pointer


this is a special kind of pointer in C++.
It contains an address of the object using which the function is invoked.
For example If you invoke Display () function of Base class using its object as shown below:

B1.Display ();

Address of object B1 is contained in this pointer and passed implicitly to display () function.

     

Following are the use of this pointer:
(1) To access the private member directly in the member function.
(2) In operator overloading when we overload unary operator using member function there is no need to pass any argument to the operator function because it is passes using this pointer.
(3) It is also used to return the object using which the function is invoked.

Download Projects


Download Programs