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 |
What Is A Default Constructor in C++ ?
When would you use a pointer? A reference?
Tell How To Check Whether A Linked List Is Circular ?
What is a virtual function in C++?
What is a memory leak in C++?
Declare a pointer to a function that takes a char pointer as argument and returns a void pointer.
Tell us the size of a float variable.
Is deconstructor overloading possible? If yes then explain and if no Then why?
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?
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.
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?