Size of an empty class.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

This was an interview question: The size of an empty class is 1 byte. Why?
Should it not be 4 bytes? Because an invisible pointer "this" is part of
every class?
 
Harish said:
This was an interview question: The size of an empty class is 1 byte. Why?
Should it not be 4 bytes? Because an invisible pointer "this" is part of
every class?

The this pointer is not part of the class it is the address of the class
instance. The sizeof an empty object is 1 so that each instance will have a
unique address.
 
Back
Top