Created
July 28, 2017 10:44
-
-
Save odeblic/c4e88b7213c8bd696883e58997fb35e9 to your computer and use it in GitHub Desktop.
Size of classes with and without a vtable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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