In this question, if you try to get Sizeof class A, it will give you the answer "4", because A has only one virtual function, so its __vptr will contain 4 bytes.
In the same way, if you try to get Sizeof of class B, it will give you the answer โ4โ, because B also has only one virtual function, so its __vptr will contain 4 bytes.
But class C inherits both classes A, while B and C have a virtual function. This way, C will get 2 __vptr pointers, and C will use the inherited __vptr for its own virtual function. Therefore, if you try to get Sizeof class C, it will give you the answer "8", because C has two virtual pointers.
And finally, class D inherits class C, so D will use the inherited __vptr for its own virtual function and because class C has sizeof '8' bytes, so sizeof D will give you an answer of "8" bytes.
iPhoneBuddy
source share