empty class

D

dost

can any budy tell me
why the size of the empty class object is 1


thank you
kapil kaushik
 
R

Rolf Magnus

dost said:
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.
 
D

Daniel T.

"dost said:
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.
 
D

dost

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
 
J

Jack Klein

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.
 
D

Daniel T.

"dost said:
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.
 
J

Jaspreet

Jack said:
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.
 

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

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top