Where does "this" pointer exist? | SoloLearn: Learn to code for FREE!

0

Where does "this" pointer exist?

It definitely isnt in the class object because sizeof(classobj) doesnt include "this" size Take for eg: Class X{ Public: int getData(). { return this->data; } int data; }; Int main() { X obj; Cout << sizeof( obj); // prints 4 } It prints 4 because sizeof(obj) = sizeof(obj.data) = 4 Why does sizeof(obj) not include the this pointer size?

8/29/2016 3:41:11 PM

Sannabasavana haraginadoni

2 Answers

New Answer

0

this is just a pointer which comes into picture when u create an object of the class. then only u can get the this pointer which points to class object itself. u can't access this variable in static methods of class as static methods are not created when objects are created, instead static methods are part of class not the object.

-1