473,394 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

why is size of empty class is 1 byte

Hello All, I have one question in mind...when you derive an empty class
and see its size it comes 1 byte,can somebody tell me why.....Thanks in
advance.
Ajay

Aug 22 '06 #1
1 2650
In article <11**********************@75g2000cwc.googlegroups. com>,
Ajay <aj**********@gmail.comwrote:
>Hello All, I have one question in mind...when you derive an empty class
and see its size it comes 1 byte,can somebody tell me why.....Thanks in
advance.
Because zero sized objects are normally not allowed so it normally
gets 1, though it could be more, it's implementation defined.
When derived from, it's implementation defined as well whether
or not it take up any space in the derived class since the
derived class won't be zero sized and no user base members would be
used since they don't exist.
--
Greg Comeau / 20 years of Comeauity! Intel Mac Port now in alpha!
Comeau C/C++ ONLINE == http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Aug 22 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: pembed2003 | last post by:
Hi all, If I have the following: class Foo{ void something(void){;} }; and then later I say: Foo f;
4
by: Sweety | last post by:
hello, why sizeof an empty class why 1 byte ? plz illustrate this ? bye
8
by: ishekara | last post by:
Hi all, An object of a class A which has no member variables and no member functions, still the size of the object is 1 byte, if there is a byte member variable then also the size of the object...
6
by: free2cric | last post by:
Hi, What will the syntax sound like for checking size of an empty class? what will be the size. Thanks, Cric
3
by: ThazKool | last post by:
Is there anyway to write a class or struct that has no storage. It only operates on a reference to an already existing type. This is actually an extension to another thread. The thread went a...
8
by: ypjofficial | last post by:
Hi all, In what way does the enumerated data type contibute to the size of a class if its part of that class? eg. #include <iostream.h> class one { public:
2
by: Harish | last post by:
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?
1
by: Ajay | last post by:
Hello All, I have one question in mind...when you derive an empty class and see its size it comes 1 byte,can somebody tell me why.....Thanks in advance. Ajay
7
by: Ajay | last post by:
Hi all, Please tell me why empty class has one Byte Size. thanks in Advance.. Ajay
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.