adspace


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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Hi friends I have experience of 6 months in website design and maintanence. Now i am looking for other IT jobs.. to switch platform. please post any interview you know in chennai.

2279


What character terminates all character array strings a) b) . c) END

1400


sir please send me bpcl previous question papers

2481


Can union be self referenced?

1269


What is the latest version on c++?

1210


draw a flowchart that accepts two numbers and checks if the first is divisible by the second.

3480


daily Routine of father

1486


Please send ford technologies placement paper 2 my mail id

2180


How c functions prevents rework and therefore saves the programers time as wel as length of the code ?

1166