Size of a class with 'this' pointer
Posted
by psvaibhav
on Stack Overflow
See other posts from Stack Overflow
or by psvaibhav
Published on 2010-03-18T07:33:54Z
Indexed on
2010/03/18
7:41 UTC
Read the original article
Hit count: 171
c++
The size of a class with no data members is returned as 1 byte, even though there is an implicit 'this' pointer declared. Shouldn't the size returned be 4 bytes(on a 32 bit machine)? I came across articles which indicated that 'this' pointer is not counted for calculating the size of the object. But I am unable to understand the reason for this. Also, if any member function is declared virtual, the size of the class is now returned as 4 bytes. This means that the vptr is counted for calculating the size of the object. Why is the vptr considered and 'this' pointer ignored for calculating the size of object?
© Stack Overflow or respective owner