What is ‘this’ Pointer (object) in C++

October 28, 2007 · Filed Under C++ Questions, Placement Questions 



Don't want to miss a single bit? Subscribe By Email for Daily Jobs

Enter your email address :

All the latest from JobsAdda on Jobsadda.com delivered to your mailbox everyday.

When a member function is called, it is automatically passed an implicit argument that is a pointer to the invoking object (that is, the object on which the function is called).This pointer is called this.

Within a member function, the members of a class can be accessed directly, without
any object or class qualification. The this pointer points to the object that invoked the member function. Also the this pointer is automatically passed to all member functions. Another thing to note is that the friend functions are not members of a class and, therefore, are not passed a this pointer. Second, static member functions do not have a this pointer. e.g.

class Stack {
int top;
int size;
Stack (int top, int size)
{
this.top = top;
this.size = size;
}
};

Related Articles


Get Latest JobsAdda.com Jobs, news & updates  via Email