#include <iostream>
class A
{
public:
int a;
virtual void f()
{
std::cout << "A::f()" << std::endl;
}
virtual void g()
{
std::cout << "A::g()" << std::endl;
}
virtual void h()
{
std::cout << "A::h()" << std::endl;
}
};
class B
{
public:
int b;
virtual void f()
{
std::cout << "B::f()" << std::endl;
}
virtual void g()
{
std::cout << "B::g()" << std::endl;
}
virtual void h()
{
std::cout << "B::h()" << std::endl;
}
};
class C
{
public:
int c;
virtual void f()
{
std::cout << "C::f()" << std::endl;
}
virtual void g()
{
std::cout << "C::g()" << std::endl;
}
virtual void h()
{
std::cout << "C::h()" << std::endl;
}
};
class D: public A , public B, public C
{
public:
int d;
virtual void f1()
{
std::cout << "D::f1()" << std::endl;
}
virtual void g1()
{
std::cout << "D::g1()" << std::endl;
}
virtual void h1()
{
std::cout << "D::h1()" << std::endl;
}
};
typedef void(*Fun)(void);
int main()
{
D* pd = new D;
std::cout << pd << std::endl;
std::cout << &pd->a << std::endl;
std::cout << &pd->b << std::endl;
std::cout << &pd->c << std::endl;
std::cout << &pd->d << std::endl;
A* pa = pd;
B* pb = pd;
C* pc = pd;
std::cout << "========================" << std::endl;
std::cout << pa << std::endl;
std::cout << pb << std::endl;
std::cout << pc << std::endl;
std::cout << "========================" << std::endl;
Fun af = (Fun)*((int*)*(int*)(pa)); (*af)(); //A::f()
Fun ag = (Fun)*((int*)*(int*)(pa)+1); (*ag)(); //A::g()
Fun ah = (Fun)*((int*)*(int*)(pa)+2); (*ah)(); //A::h()
Fun bf = (Fun)*((int*)*(int*)(pb)); (*bf)(); //B::f()
Fun bg = (Fun)*((int*)*(int*)(pb)+1); (*bg)(); //B::g()
Fun bh = (Fun)*((int*)*(int*)(pb)+2); (*bh)(); //B::h()
Fun cf = (Fun)*((int*)*(int*)(pc)); (*cf)(); //C::f()
Fun cg = (Fun)*((int*)*(int*)(pc)+1); (*cg)(); //C::g()
Fun ch = (Fun)*((int*)*(int*)(pc)+2); (*ch)(); //C::h()
Fun df1 = (Fun)*((int*)*(int*)(pd)+3); (*df1)(); //D::f1()
Fun dg1 = (Fun)*((int*)*(int*)(pd)+4); (*dg1)(); //D::g1()
Fun dh1 = (Fun)*((int*)*(int*)(pd)+5); (*dh1)(); //D::h1()
system("pause");
return 0;
}