1. C++ uses a unique keyword called “this” to represent an object that invokes a member function. 2. This unique pointer is automatically passed to a member function when it is invoked. 3. “this” is a pointer that always point to the object for which the member function was called . 4. For example, the function call A.max () will set the pointer “this” to the address of the object A. Next time suppose we call B.max(), the pointer “this” will store address of object B.
Consider the following example:
#include<conio.h>
#include<iostream>
class sample
{
int a;
public:
void setdata(int x)
{
this ->a=x;
}
void putdata()
{
cout<<this ->a;
}
};
void main()
{
clrscr();
sample s;
s.setdata(100);
s.putdata();
getch();
}