当前位置:网站首页>4.2 Virtual Member Functions
4.2 Virtual Member Functions
2022-07-28 21:11:00 【CCSUZB】
virtual function
General implementation model : Every class There is one virtual table, Include this class There is a role in virutal function
The address of , Then each object
There is one vptr
, Point to virtual table
Where ; Consider the following code :
class Point {
public:
virtual ~Point();
virtual Point& mult(float) = 0;
float x() const {
return _x;}
virtual float y() const {
return 0;}
virtual float z() const {
return 0;}
protected:
Point(float x = 0.0);
float _x;
};
class Point2d : public Point{
public:
Point2d(float x = 0.0, float y = 0.0) :
Point(x), _y(y){
}
~Point2d();
Point2d& mult(float);
float y() const {
return _y;}
protected:
float _y;
};
class Point3d : public Point2d{
public:
Point3d(float x = 0.0, float y = 0.0, float z = 0.0) :
Point2d(x, y), _z(z){
}
~Point3d();
Point& mult(float);
float z() const {
return _z;}
protected:
float _z;
};
The following figure for Point
Memory layout and its virtual table
Under multiple inheritance virutal functions
class Base1 {
public:
Base1();
virtual ~Base1();
virtual void speakClearly();
virtual Base1 *clone() const;
protected:
float data_Base1;
};
class Base2 {
public:
Base2();
virtual ~Base2();
virtual void mumble();
virtual Base2 *clone() const;
protected:
float data_Base2;
};
class Derived : public Base1, public Base2 {
public:
Derived();
virtual Derived *clone() const;
protected:
float data_Derived;
};
边栏推荐
- (转)冒泡排序及优化详解
- Unity foundation 5-optimization strategy
- After Europe, it entered Japan and South Korea again, and the globalization of Pico consumer VR accelerated
- Fragment中使用ViewPager滑动浏览页面
- 【周周有奖】云原生编程挑战赛“边缘容器”赛道邀你来战!
- 【input 身份证号】星号 代替,input 切割成 多个 小格格(类似)
- 又一款装机神器
- Space game Lesson 12: shield
- Understanding of C # delegate
- ZCMU--5066: 黑暗长廊
猜你喜欢
Unity - Fundamentals of 3D mathematics
数据库--explain的使用
BUUCTF做题Upload-Labs记录pass-11~pass-20
Unity3d tutorial notes - unity initial 04
MoCo V2:MoCo系列再升级
Efficientformer: lightweight vit backbone
Unity foundation 6-rotation
Cause analysis of restart of EMC cx4-120 SPB controller
【TiDB】txt文档导入数据库,这样做真的很高效
Explain the camera in unity and its application
随机推荐
Link with bracket sequence I (state based multidimensional DP)
C # basic 4-written examination question 1
Unity3d tutorial notes - unity initial 03
融合数据库生态:利用 EventBridge 构建 CDC 应用
Two written interview questions about regular
ctfshow 网络迷踪做题记录(2)
Dom4J的Bug
MoCo V3:视觉自监督迎来Transformer
Eureka registers with each other, only showing each other or only showing problems in one
向往的开源之多YOUNG新生 | 从开源到就业的避坑指南来啦!
Space shooting Lesson 10: score (painting and writing)
What is "security"? Volvo tells you with its unique understanding and action
C language function program example (super complete)
速卖通测评自养号,国外环境如何搭建?需要多少成本?
Mobilevit: challenge the end-to-side overlord of mobilenet
Unity foundation 3- data persistence
Fragment中使用ViewPager滑动浏览页面
Zcmu--5066: dark corridor
C # basic 5-asynchronous
C # basic 1-events and commissions