Given:
class A
{
};
class B : A // inherit from an empty class
{
int * x;
};
class C
{
int * x;
};
Is sizeof(B) == sizeof(C)
according to standards?
While sizeof(A) == 1
, the 1 is a "dummy" value because sizeof cannot return 0 in this case
According to standards, is the dummy value carried forward during inheritance from a non empty class.
On a practical note, the reason for the question is that I am using void *
as a pointer to several classes, and it would be clearer if they all shared a base class, but this is performance critical code and adding one byte, would actually add 8 because of alignment with a 64 bit pointer in the child class. That will significantly add to the total memory footprint and I will potentially have a large number of them.