By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,534 Members | 2,223 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,534 IT Pros & Developers. It's quick & easy.

Size of an empty class.

P: n/a
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?
Jun 15 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Harish" <Ha****@discussions.microsoft.com> wrote in message
news:52**********************************@microsof t.com...
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.
--
Jeff Partch [VC++ MVP]
Jun 15 '06 #2

P: n/a
> 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?


There was an extensive discussion about this topic last month in the thread
'Question about sizeof a class.'
google archive:
http://groups.google.be/group/micros...74822ed72091bc

--

Kind regards,
Bruno van Dooren
br**********************@hotmail.com
Remove only "_nos_pam"
Jun 15 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.