How many v_tables exist for a class that inherits twice
struct A
{
virtual void f1() {}
};
struct B: public A {};
struct C: public A {};
struct D: public B,public C {};
int main()
{
cout<<sizeof(A)<<" "<<sizeof(B)<<" "<<sizeof(C)<<" "<<sizeof(D)<<endl;
cout<<"_______"<<endl;
return 0;
}
-
Result on my system (c9.o):
8 8 8 16
Does this mean D has 2 virtual pointers to 2 virtual tables? If so, where are the pointers? -
If we remove the fucntion
f1
ofstruct A
, the output will be as follows:1 8 8 16
. The same question is being asked here. -
If we do not remove
f1
, and nowB
andC
inherit the virtual machine fromA
the result:8 8 8 16
. The same question is being asked here.
source to share
No one has answered this question yet
Check out similar questions: