473,327 Members | 2,025 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,327 software developers and data experts.

size of a class containg both data and function

Please help me
what should be the size of a class,if it contains data member of int and float,
a function,when we crete an object?
For example
Expand|Select|Wrap|Line Numbers
  1. class X
  2. {
  3.     int a ;
  4.     float b;
  5.    public:
  6.          void getdata(int x,float y)
  7.          {
  8.             a = x;
  9.             b = y;
  10.          }
  11.  
  12. };
  13. int main()
  14. {
  15.    X p;
  16.   sizeof(p);
  17. }
Oct 23 '07 #1
3 1035
amitpatel66
2,367 Expert 2GB
Please help me
what should be the size of a class,if it contains data member of int and float,
a function,when we crete an object?
For example
class X
{
int a ;
float b;
public:
void getdata(int x,float y)
{
a = x;
b = y;
}

};
int main()
{
X p;
sizeof(p);
}
What is the value that you are getting with sizeof() function??
Oct 23 '07 #2
What is the value that you are getting with sizeof() function??
Actually what should be the size means how many bites the class will take when the object is created.
By the way i have not executed the code that i have given ...........plz can u help
Oct 24 '07 #3
Banfa
9,065 Expert Mod 8TB
Actually what should be the size means how many bites the class will take when the object is created.
By the way i have not executed the code that i have given ...........plz can u help
amitpatel66 is aware of what the question is and what the size of a variable/type means.

They were suggesting that you can easily answer your own question by simply running the code.

Once you have run the code and got the result you could try and explain that result to yourself (or us) and if you are confused at that stage we can help you.

The actual answer to your question, "what should be the size of that class" is that we can't tell without knowing what platform you are using and what structure packing rules it is using.
Oct 24 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: vijay | last post by:
I have a doubt with size of classed with virtual functions I have declared A,A1,A2 ,B , C, D some classes with no varaibles but a vitual function each, The size of A is as expected 4 bytes with...
18
by: Tarundeep | last post by:
hi, let us say it is a 32 bit processor then the size of the pointer is 32 bits. now i want to know what would be the size of the class with vtable pointer in it , that is it has few virtual...
6
by: dddddddd2444444 | last post by:
Hi,please help... It works fine when I define a 2-D array like char code. But it won't work when I try to define the array dynamically using a function. It just crashes. Does anyone know why?...
6
by: Dennis C. Drumm | last post by:
Is there a way to keep track of how much memory a stack object is consuming, considering it may contain a wide variety of objects that do not easily lend themselves to computing a size? Thanks,...
4
by: tshad | last post by:
I am having trouble with links in my DataGrid. I have Links all over my page set to smaller and they are consistant all over the page in both Mozilla and IE, except for the DataGrid. Here is a...
11
by: mast2as | last post by:
This question has been posted to this forum before and I read the thread but found that the answers were perhaps imcomplete, so I am trying again. Whenever I am creating objects I would like to...
4
by: =?iso-8859-1?B?UmVu6SBKZW5zZW4=?= | last post by:
Hello I got a problem with a class i'm trying to create. the problem is that i would like to use the dot when i access some parametes in the class like. Connect()
3
by: mweltin | last post by:
I have a derived class that extends a base class by adding a float member. The strange part is when I use the STL sort algorithm on a vector of derived classes, only hte float member is sorted....
1
by: chrisj | last post by:
I'm using freeASPupload and got some assistance integrating to a Member script. It works successfully. In this modified version there are two groups that use this upload script. Members of one...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.