From what i know, the size of a class in c++ depends on the below factors -
The Itanium ABI uses the C++03 definition of POD to define classes that are "POD for the purposes of layout". Having private data members disqualifies a class from being an aggregate and therefore POD in C++03:
A POD-struct is an aggregate class that has no non-static data members of type non-POD-struct, non-POD-union (or array of such types) or reference, and has no user-defined copy assignment operator and no user-defined destructor.
Being a POD class disables tail padding reuse:
The dsize, nvsize, and nvalign of these types are defined to be their ordinary size and alignment. These properties only matter for non-empty class types that are used as base classes. We ignore tail padding for PODs because an early version of the standard did not allow us to use it for anything else and because it sometimes permits faster copying of the type.
Thus, in your first example, A
is not a POD for layout purposes and its tail padding can be used for B::c
, but in your second example, it is a POD, and its tail padding cannot be reused.