424,948 Members | 795 Online
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

# empty class

 P: n/a can any budy tell me why the size of the empty class object is 1 thank you kapil kaushik Apr 11 '06 #1
7 Replies

 P: n/a dost wrote: can any budy tell me why the size of the empty class object is 1 Because in C++, every object has a unique address. Now consider what happens if you make an array of zero-sized objects. Apr 11 '06 #2

 P: n/a In article <11**********************@g10g2000cwb.googlegroups .com>, "dost" wrote: can any budy tell me why the size of the empty class object is 1 Objects exist, therefore they take up space. sizeof tells you how big they are. If an object were to have sizeof == 0 then it would not exist. -- Magic depends on tradition and belief. It does not welcome observation, nor does it profit by experiment. On the other hand, science is based on experience; it is open to correction by observation and experiment. Apr 11 '06 #3

 P: n/a Just imagine how bad a programmers life will be if size of empty class is 0. U created a many objects of an empty classes and all are having same address!!! Link to wht stroustrup says... http://public.research.att.com/~bs/b...l#sizeof-empty ~K2G dost wrote: can any budy tell me why the size of the empty class object is 1 thank you kapil kaushik Apr 11 '06 #4

 P: n/a if the size of empty class object is "1"....and if we declare some..variable..in it suppose int then its..size change....only the size of the variable will matter...where the difault size gone example class empty { int a;} its object size will be 2.....where the difault size gone thanks Apr 11 '06 #5

 P: n/a On 11 Apr 2006 03:16:37 -0700, "dost" wrote in comp.lang.c++: can any budy tell me why the size of the empty class object is 1 The size of an empty class object is not necessarily 1. It is merely required to be greater than 0. -- Jack Klein Home: http://JK-Technology.Com FAQs for comp.lang.c http://c-faq.com/ comp.lang.c++ http://www.parashift.com/c++-faq-lite/ alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html Apr 12 '06 #6

 P: n/a In article <11**********************@j33g2000cwa.googlegroups .com>, "dost" wrote: if the size of empty class object is "1"....and if we declare some..variable..in it suppose int then its..size change....only the size of the variable will matter...where the difault size gone example class empty { int a;} its object size will be 2.....where the difault size gone thanks Who says there ever was a default size? The size of an object is either 1 or the sum of the sizeof each contained element (possibly plus some padding,) whichever is greater. -- Magic depends on tradition and belief. It does not welcome observation, nor does it profit by experiment. On the other hand, science is based on experience; it is open to correction by observation and experiment. Apr 12 '06 #7

 P: n/a Jack Klein wrote: On 11 Apr 2006 03:16:37 -0700, "dost" wrote in comp.lang.c++: can any budy tell me why the size of the empty class object is 1 The size of an empty class object is not necessarily 1. It is merely required to be greater than 0. -- Size of an empty class object is >= 1. However, an empty base-class component of a derived classes can be size 0. Apr 12 '06 #8

### This discussion thread is closed

Replies have been disabled for this discussion.