What is Advantage and Use of THIS pointer in C++ – Scenarios?



What is Advantage and Use of THIS pointer in C++ – Scenarios?..

Answer / Atul Kumar Tripathi

"The 'this' pointer in C++ serves multiple purposes:
1. Accessing member variables: Within a non-static member function, 'this' can be used to access the object's instance variables.
2. Dot (.) operator override: In some cases, you may want to override the dot (.) operator for better readability or specific functionality. The 'this' pointer is useful in such scenarios.
3. Invoking other member functions: You can use 'this' pointer to call other member functions of the same class.
4. Dynamically calling constructors: In a derived class, you can use 'this' pointer to call constructors of the base class.
5. Scope resolution operator (::) override: You can use 'this' pointer along with the scope resolution operator to avoid ambiguities in function overloading and namespace conflicts."n

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ Interview Questions

What Is A Default Constructor in C++ ?

1 Answers   Amazon,


When would you use a pointer? A reference?

1 Answers   Amazon,


Tell How To Check Whether A Linked List Is Circular ?

1 Answers   IBS, Infosys,


What is a virtual function in C++?

1 Answers   C DAC,


What is a memory leak in C++?

1 Answers   Agilent,


Declare a pointer to a function that takes a char pointer as argument and returns a void pointer.

1 Answers   Alter,


Tell us the size of a float variable.

1 Answers   Accenture,


Is deconstructor overloading possible? If yes then explain and if no Then why?

2 Answers  


What are "pure virtual" functions?

1 Answers   Adobe, Alter, iNautix,


How does stack look in function calls? When does stack overflow? What can you do to remedy it?

1 Answers   Adobe,


Execute the qsort () in c/sort() in c++ library or your own custom sort which will sort any type of data on user defined criteria.

1 Answers   Adobe,


Implement a 2D bit-matrix representing monochrome pixels which will have only OFF/ON values and will take on an average only one bit of memory for each stored bit. How to perform various operations on it?

1 Answers   Adobe,


Categories