Define This pointer? Implement this pointer with an example


what is meant by 'this' operation? write a C++ program to demonstrate how this pointer is employed to access the member of knowledge class

This Pointer 

This pointer : C++ uses a singular keyword called this to represent an object an object that invokes a member function, this is often a pointer at points to the thing that this function was called. for instance , this is often a call A.max() will set to pointer this to the address of the thing A. The starting address is that the same because the address of the primary variable within the social organization . 

This unique pointer is automatically passed to a member function when it's called. The pointer This acts as an implicit argument to all or any the member functions 

Consider the subsequent simple example:
 class ABC
{
 int a ;
..........
.........
};
The private variable 'a' are often used directly inside a member function , like 
a= 123;
we can also use the subsequent statement to try to to an equivalent job :
this ->a=123;


since c++ permits the utilization of shorthand form a=123. we've not been using the pointer this explicitly thus far . However, we've been implicitly using the pointer this when overloading the operators using member function.


When a binary operator in overloaded employing a member function we pass just one argument to the function.the other arguments is implicitly passed using the pointer this. One important application of the pointer is is to return the object it point to. for instance ,
              return *this;
Inside a member function will return the thing that invoked the function. This statement resumes importance once we want to match two or more objects inside a member function and return the invoking object as a result.


0 Comments