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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top