1.1. Virtual member function 1.1.1. Single inherited virtual member function 0001 Class Point0002 {0003 public: 0004 Virtual ~ Point (); 0005 Virtual Point & Mult (FLOAT) = 0; 0006 float x () const {return_x} ; 0007 Virtual float y () const {return 0}; 0008 Virtual float z () const {return 0}; 0009 protected: 0010 Point (float x = 0.00) 0011 float _x; 0012}; 0013 Class Point2d: public point0014 { 0015 public: 0016 Point2D (float x = 0.00, float y = 0.00): Point (x), y (_y) {}; 0017 Virtual ~ Point2D (); 0018 // Rewinding the base class virtual function 0019 Point2D & Mult (Float) ); 0020 float y () const {return_y}; 0021 protected: 0022 float _y; 0023}; 0024 Class Point3d: public point2d0025 {0026 public: 0027 Point3D (float x = 0.00, y = 0.00, z = 0.00): Point2D (x, y), z (_z) {}; 0028 Virtual ~ Point3d (); 0029 // Overwritten the virtual function 0030 Point3D & Mult (float); 0031 float z () const {return_z}; 0032 protected : 0033 Float_Z; 0034};
The object model is as follows: Point Object Point Virtual Function Talbe
_X _VPTR_POINT
# 0 TYPE_INFO for Point # 1 Point :: ~ Point () # 2 Pure Vitual Called (Place) # 3 Point :: Y () # 4 Point :: Z () Point2D Object Point2D Virtual Function Talbe
Point SubObject
_X _vptr_point _y
# 0 TYPE_INFO for Point2D # 1 Point2D :: ~ Point2D () # 2 Point2d :: Mult () # 3 Point2d :: Y () # 4 Point2D :: z () Point3D Object Point3D Virtual Function Talbe
Point2D SubObject_x _vptr_point _y _z
# 0 TYPE_INFO for Point3D # 1 Point3D :: ~ Point3D () # 2 Point3D :: Mult () # 3 Point2d :: Y () // Inheritance # 4 point3d :: z ()