473,785 Members | 2,297 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 6000
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************ **********@g10g 2000cwb.googleg roups.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.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Apr 12 '06 #6
In article <11************ **********@j33g 2000cwa.googleg roups.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
1670
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 of size 0, then: - an object of type foo may lie at the same address as another. - arrays of foo objects would have size 0, and pointer arithmetic on array cell would break. - requirements of the standard explicitly stating objects have
3
3596
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 be "public interface Value{}" in Java! class IntValue : public Value{ private: int _value; public:
12
17115
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. This is okay in some cases (such as <tbody>), but problematic for other tags (such as <option>). Some tags (td, th, ...) do not produce warnings when they are empty.
9
2374
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
2658
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 = Color.Empty then..... or if mycolor is Color.Empty then .......
4
2579
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 enum might suffice since we aren't sending any data with the exception - but that's sort of off-topic I suppose): class Whoops{}; class GeeDontKnowHowToDoThat{};
8
5749
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
34885
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 string) for a string if the corresponding element is missing in the XML. Input XML: <DemoClass><A>some value</A><B></B><DemoClass>
26
2796
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
6130
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 what information I put it always add records to database when I click on submit. What can I do to make sure user will not be able to add records to database until he enters the right information? I am posting my code for you guys to have a look...
0
9647
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9489
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10162
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9959
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7509
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4061
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 we have to send another system
2
3665
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.