Class sizes with virtual inheritance in C++
#include<iostream> using namespace std; class abc { int a; }; class xyz : public virtual abc { int b; }; int main() { abc obj; xyz obj1; cout<<endl<<sizeof(obj); cout<<endl<<sizeof(obj1); return 0; } The answers would be compiler dependent but I'm surprized when I saw this as the result ~/Documents/workspace/tmp ‹.rvm-› $ ./class_sizes 4 16 If I remove the virtual keyword then the size allocated is 4 and 8 respectively which is what I expected. Why is the extra space being taken up exactly? I suspect it is for the vptr table or something of that sorts but don't know for certain. A good article