Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren0
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?
2 Antworten
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
pasir