What is ‘this’ Pointer (object) in C++
![]() Don't want to miss a single bit? Subscribe By Email for Daily Jobs |
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
- What are Virtual Functions ? Why do we need Virtual Functions? Explain with an example.
- What are static Data and Static Member Functions in C++ ?
- What are Friend Functions and Friend Classes in C++ ?
- What are Constructors and Destructors in C++ ?
- What do you mean by “Pointers to Function”? What are Function Pointers ?


