473,503 Members | 1,638 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

empty class

can any budy tell me
why the size of the empty class object is 1
thank you
kapil kaushik

Apr 11 '06 #1
7 5986
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
In article <11**********************@g10g2000cwb.googlegroups .com>,
"dost" <ka**************@gmail.com> 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
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
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
On 11 Apr 2006 03:16:37 -0700, "dost" <ka**************@gmail.com>
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
In article <11**********************@j33g2000cwa.googlegroups .com>,
"dost" <ka**************@gmail.com> 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

Jack Klein wrote:
On 11 Apr 2006 03:16:37 -0700, "dost" <ka**************@gmail.com>
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1653
by: Emmanuel Thomé | last post by:
This is a comment aside the empty class behavior FAQ. I understand there are a fair number of reasons which make empty classes have non-zero size (except as base classes). If ``class foo'' were...
3
3582
by: Markus Dehmann | last post by:
I have a two different value types with which I want to do similar things: store them in the same vector, stack, etc. Also, I want an << operator for each of them. class Value{}; // this would...
12
17077
by: Stefan Weiss | last post by:
Hi. (this is somewhat similar to yesterday's thread about empty links) I noticed that Tidy issues warnings whenever it encounters empty tags, and strips those tags if cleanup was requested....
9
2359
by: Søren M. Olesen | last post by:
Hi Can someone tell me how to implement something similar to String.Empty ?? Given a class called myValue Public class myValue private id as integer private value as string end class
19
2620
by: Dennis | last post by:
I have a public variable in a class of type color declared as follows: public mycolor as color = color.Empty I want to check to see if the user has specified a color like; if mycolor =...
4
2556
by: avranju | last post by:
Hi, We have a few exception marker classes in a project that are used only to throw exceptions. I mean stuff like this (this may not be such a hot idea for doing exception handling - a simple...
8
5707
by: meendar | last post by:
what will a object of an Empty class( contain nothing), do on default.What are all the default methods it calls. what is the use of creating the object for an empty class?
7
34761
by: kumar.senthil | last post by:
Hi, I'm using XmlSerializer to create an object from the XML string. I would like to know whether I can get a null value for an empty XML element. Actually the XmlSerializer assigns "" (empty...
26
2734
by: anonieko | last post by:
In the past I always used "" everywhere for empty string in my code without a problem. Now, do you think I should use String.Empty instead of "" (at all times) ? Let me know your thoughts.
9
6103
by: Dhiru1009 | last post by:
Hi guys, I am trying to build a user registration form using PHP and MYSQL but encountring a problem. When I click on submit with empty fields it adds records to database also it doesn't matter...
0
7202
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
7086
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
7332
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...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.