top of page

why size of empty class object contains 1 byte in c++?



Compiler allocate 1 byte of memory of empty class object for unique address identification. So, if a class have multiple objects they can have different unique memory location.

Means for differentiate the objects of empty class compiler allocate 1 byte of memory.

Size of Empty Class in C++ with virtual function :

If empty class contains virtual function then size of empty class object will be 4 byte because of virtual pointer.

Note: Every virtual function contains one virtual pointer.

Comments


bottom of page