freelanceprogrammers.org Forum Index » C

Doubt in Size of Class ??


View user's profile Post To page top
shabbir_saiyed@... Posted: Fri Jul 18, 2003 4:48 pm


Joined: 10 Jul 2003

Posts: 4
Doubt in Size of Class ??
Compiler :
Turbo C++ 3.0 ,
Visual C++ 6.0,
Borland C++ 5.02 ,
G++ 2.x

Hello friends,
I have compiled my program on all above compiler
but i`m getting same answer `1` .why?
if you declare char variable inside class definition then also
answer is same `1` .why?
why size of empty class is one ?? why not zero ???
why compiler need atleast one byte to define a class ???
please clear my doubt .



#include<iostream.h>
class abc
{
};
int main()
{
cout<< sizeof(abc);
return 0;
}
___________________________________________________
Download the hottest & happening ringtones here!
OR SMS: Top tone to 7333
Click here now:
http://sms.rediff.com/cgi-bin/ringtone/ringhome.pl
Reply with quote
Send private message
View user's profile Post To page top
tvmanikandan Posted: Fri Jul 18, 2003 4:55 pm


Joined: 18 Jul 2003

Posts: 2
Doubt in Size of Class ??
If the class has size ZERO then all the instances ( ie ,objects)refer to the
same location.So while deleting the objects it will become a problem.
So,As a minimum the compiler allocates 1 byte for the class if it doesn`t have
any member/virtual function.

Mani
______________________________ Reply Separator _________________________________
Subject: *[&Programmers-Town&]* Doubt in Size of Class ??
Author: shabbir.saiyed (shabbir_saiyed@...) at internet
Date: 7/18/03 5:18 PM


Compiler :
Turbo C++ 3.0 ,
Visual C++ 6.0,
Borland C++ 5.02 ,
G++ 2.x

Hello friends,
I have compiled my program on all above compiler
but i`m getting same answer `1` .why?
if you declare char variable inside class definition then also
answer is same `1` .why?
why size of empty class is one ?? why not zero ???
why compiler need atleast one byte to define a class ???
please clear my doubt .



#include<iostream.h>
class abc
{
};
int main()
{
cout<< sizeof(abc);
return 0;
}
___________________________________________________
Download the hottest & happening ringtones here!
OR SMS: Top tone to 7333
Click here now:
http://sms.rediff.com/cgi-bin/ringtone/ringhome.pl





To unsubscribe from this group, send an email to:
Programmers-Town-unsubscribe@yahoogroups.com



Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help