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?

29th Aug 2016, 3:41 PM
Sannabasavana haraginadoni
Sannabasavana haraginadoni - avatar
2 Answers
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.
21st Oct 2016, 9:42 PM
PANKAJ KUMAR
PANKAJ KUMAR - avatar
- 1
pasir
4th Sep 2016, 12:57 PM
Ayoub Barnoss
Ayoub Barnoss - avatar