- #include <iostream>
- using namespace std;
- class point
- {
- public:
- point(float a):x(a){}
- virtual void f(){cout << "point::f() called" << endl;}
- virtual void g(){cout << "point::g() called" << endl;}
- void h(){cout << "point::h() called" << endl;}
- public:
- float x;
- };
- class point2D:public point
- {
- public:
- point2D(float a,float b):point(a),y(b){}
- void g(){ cout << "point2D::g() called" << endl;}
- virtual void z(){cout << "point2D::z() called" << endl;}
- private:
- float y;
- };
- int main()
- {
- point2D t(5,6);
- typedef void (*PFUN)();
- PFUN pfun;
- pfun = (PFUN)(*(int*)(*(int*)(&t)));
- pfun();
- pfun = (PFUN)(*((int*)(*(int*)(&t))+1));
- pfun();
- pfun = (PFUN)(*((int*)(*(int*)(&t))+2));
- pfun();
- cout << *(float*)((float*)(&t)+1)<< endl;
- cout << *(float*)((float*)(&t)+2)<< endl;
- return 0;
- }
point的对象模型:
4B vptr -----------------> point::f();
4B float x; point::g();
point2D的对象模型:
4B vptr----------------->point::f();
4B point::x; point2D::g():
4B point2D::y; point2D::z();