A
Anarki
##include <iostream>
using namespace std;
class A
{
};
class B:virtual public A
{
};
class C:virtual public A
{
};
class D
ublic B, public C
{
};
int main()
{
cout << "Sizeof(A) " << sizeof(A) << endl;
cout << "Sizeof(B) " << sizeof(B) << endl;
cout << "Sizeof(C) " << sizeof(C) << endl;
cout << "Sizeof(D) " << sizeof(D) << endl;
return 0;
}
usually virtual inheritance comes into action to resolve the ambiguty
of data access of grandparent class when there exist more than 1 path
between grandparent and grandchild.
Ok i take it as granted VI resolves data access ambiguity.
But please take look at the output of the program i gave
1
4 //Any virtual pointer to a virtual function table? Note i havent
specified and virtual functions
4 //Any virtual pointer to a virtual function table? Note i havent
specified and virtual functions
8 //Two vptrs of B and C??
if there are vptrs what is their role in avoiding the data access
ambiguity?
i will also give another analysis of memory structure with and without
virtual inheritance.
using namespace std;
class A
{
};
class B:virtual public A
{
};
class C:virtual public A
{
};
class D
{
};
int main()
{
cout << "Sizeof(A) " << sizeof(A) << endl;
cout << "Sizeof(B) " << sizeof(B) << endl;
cout << "Sizeof(C) " << sizeof(C) << endl;
cout << "Sizeof(D) " << sizeof(D) << endl;
return 0;
}
usually virtual inheritance comes into action to resolve the ambiguty
of data access of grandparent class when there exist more than 1 path
between grandparent and grandchild.
Ok i take it as granted VI resolves data access ambiguity.
But please take look at the output of the program i gave
1
4 //Any virtual pointer to a virtual function table? Note i havent
specified and virtual functions
4 //Any virtual pointer to a virtual function table? Note i havent
specified and virtual functions
8 //Two vptrs of B and C??
if there are vptrs what is their role in avoiding the data access
ambiguity?
i will also give another analysis of memory structure with and without
virtual inheritance.