classes

what is the size of this empty class?

class A
{
};

int main()
{
A a;
cout < < sizeof(a);

what is the size of class B here?

class A
{

};
class B:public A
{
};
int main()
{
B b;
cout< < sizeof(b) ; return 0; } the size of B is also a 1. even though B is inherited from class A , which doesnt have data members, class B size will be 1. similarly if any empty class say C, is inherited from empty class B, then the size of class C would be only 1 .

Next Page

No comments: