Skip to content

Instantly share code, notes, and snippets.

@odeblic
Created July 28, 2017 10:44
Show Gist options
  • Save odeblic/c4e88b7213c8bd696883e58997fb35e9 to your computer and use it in GitHub Desktop.
Save odeblic/c4e88b7213c8bd696883e58997fb35e9 to your computer and use it in GitHub Desktop.
Size of classes with and without a vtable
#include <iostream>
struct A
{
};
struct B : A
{
};
struct Bv : virtual A
{
};
struct C : A
{
};
struct Cv : virtual A
{
};
struct D : B, C
{
};
struct Dv : virtual B, virtual C
{
};
#define PRINT(T) std::cout << "size of " #T " is:\t" << sizeof(T) << std::endl;
int main()
{
PRINT(A);
PRINT(B);
PRINT(Bv);
PRINT(C);
PRINT(Cv);
PRINT(D);
PRINT(Dv);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment