When sizeof is applied to an empty class type, the result is always 1.
When sizeof is applied to a class type, the result is the size of an object of that class plus any additional padding required to place such object in an array.
When sizeof is applied to an expression that designates a polymorphic object, the result is the size of the static type of the expression.
Run the following C++ code to see above result.
#include <iostream>
using namespace std;
struct Empty {};
struct Base { int a; };
struct Derived : Base { char b; };
int main()
{
Empty e;
Derived d;
Base& b = d;
std::cout << "size of empty class: " << sizeof e << '\n'
<< "size of the Derived: " << sizeof d << '\n'
<< "size of the Derived through Base: " << sizeof b << '\n';
cin.get();
}
output: