this is kind of homework question. For the following code,
#include <iostream>
using namespace std;
class A
{
public:
virtual void f(){}
};
class B
{
public:
virtual void f2(){}
};
class C: public A, public B
{
public:
virtual void f3(){}
};
class D: public C
{
public:
virtual void f4(){}
};
int main()
{
cout<<sizeof(D)<<endl;
}
The output is: 8
Could anyone please explain how it is 8 bytes? If the vtable implementation is compiler dependent, what should I answer for this kind of question in interviews? What about virtual base classes?
EDIT: i am working on a 32-bit platform.