I'm not sure I understand your questions.
The size of a class has a size of the sum of all its members (at least -- it's possible for the size to be even larger than that due to other things, like vtables, padding, etc).
In the case of inheritance, child classes have everything their parents have (it's all inherited).
So in this case:
1 2 3 4 5 6 7
|
class Parent
{
int i;
};
class Child : public Parent
{};
| |
Here, Parent has a size of
at least sizeof(int) (which is often 4)
Child also has a size of
at least sizeof(int), since it contains 1 int (Parent::i)
If we change that to something like the below:
1 2 3 4 5 6 7 8 9
|
class Parent
{
int i;
};
class Child : public Parent
{
int j;
};
| |
Now, Parent contains 1 int (i), and Child contains two ints (i, j).
so sizeof(Parent) >= sizeof(int)
and sizeof(Child) >= (2 * sizeof(int))