I have a simple class in C++ that has an integer and a vtable:
class Something {
virtual void sampleVirtualMethod();
int someInteger;
};
If you look at the object layout for MSVC (using the /d1reportSingleClassLayout) you get:
class Something size(8):
+---
0 | {vfptr}
4 | someInteger
+---
Which makes complete sense. 4 bytes for the vtable pointer and 4 bytes for the integer. The weird thing is when I add a double to the class:
class Something {
virtual void sampleVirtualMethod();
int someInteger;
**double someDouble;**
};
I get this object layout:
class Something size(24):
+---
0 | {vfptr}
8 | someInteger
| <alignment member> (size=4)
16 | someDouble
+---
Why is the difference between the 0 offset and someInteger 8 instead of 4? Did the vtable grow to 8 bytes somehow? No matter the order of when I add a double, this happens.
Thanks.