标签:proc title tty int sdn text include each his
#include <iostream>
using namespace std;
class Base
{
public:
virtual void fun1()
{
cout << "Base::fun1()" << endl;
}
virtual void fun2()
{
cout << "Base::fun2()" << endl;
}
};
class Son : public Base
{
public:
void fun1()
{
cout << "Son::fun1()" << endl;
}
};
void Deal(int *p)
{
typedef void(*Pfun)();//函数指针。
//再次记住每张虚表后面的结束符是0(NULL)。
for (int i = 0; p[i] != NULL; i++)
{
Pfun fun = (Pfun)p[i];
fun();
}
}
void test()
{
Base b;
Son s;
int *p = (int *)*((int *)(&b));//此处是虚表的地址。
Deal(p);//将虚表地址传入。
}
int main()
{
test();
return 0;
}
标签:proc title tty int sdn text include each his
原文地址:http://www.cnblogs.com/yangykaifa/p/7219717.html