#include <iostream>
using
namespace
std;
class A
{
public:
A(
int a1=
0,
int a2=
0):a1(a1),a2(a2){}
virtual void f(){
cout<<
"A::f()"<<
endl;}
virtual void Af(){
cout<<
"A::Af()"<<
endl;}
int a1;
int a2;
};
class B1:
virtual
public A
{
public:
B1(
int a1=
0,
int a2=
0,
int b1=
0):A(a1,a2),b1(b1){}
virtual void f(){
cout<<
"B1::f()"<<
endl;}
virtual void f1(){
cout<<
"B1::f1()"<<
endl;}
virtual void Bf1(){
cout<<
"B1::Bf1()"<<
endl;}
int b1;
};
class B2:
virtual
public A
{
public:
B2(
int b2=
0):b2(b2){}
virtual void f(){
cout<<
"B2::f()"<<
endl;}
virtual void f2(){
cout<<
"B2::f2()"<<
endl;}
virtual void Bf2(){
cout<<
"B2::Bf2()"<<
endl;}
int b2;
};
class C:
public B1,
public B2
{
public:
C(
int a1=
0,
int a2=
0,
int b1=
0,
int b2=
0,
int c1=
0):B1(
1,
2,
3),B2(
6),c1(
7){}
virtual void f(){
cout<<
"C::f()"<<
endl;}
virtual void f1(){
cout<<
"C::f1()"<<
endl;}
virtual void f2(){
cout<<
"C::f2()"<<
endl;}
virtual void Cf(){
cout<<
"C::Cf()"<<
endl;}
int c1;
};
typedef void (*pfun)();
int main(void)
{
C *cp=
new C;
cout<<
sizeof(*bp)<<
endl;
pfun fun=
NULL;
cout<<
"The B1's virtual table->"<<
endl;
for(
int i=
0;i<
5;i++)
{
fun=(pfun)*((
long*)*(
long*)cp+i);
fun();
}
long* p=(
long*)cp+
2;
cout<<
"The B2's virtual table->"<<
endl;
for(
int i=
0;i<
3;i++)
{
fun=(pfun)*((
long*)*(
long*)p+i);
fun();
}
cout<<
"The A2's virtual table->"<<
endl;
A *ap=
reinterpret_cast<A*>((
long*)cp+
4);
for(
int i=
0;i<
2;i++)
{
fun=(pfun)*((
long*)*(
long*)ap+i);
fun();
}
return
0;
}