当前位置:网站首页>4.2 Virtual Member Functions
4.2 Virtual Member Functions
2022-07-28 19:06:00 【CCSUZB】
virtual function一般实现模型:每个class有一个virtual table, 内含该class之中有作用的virutal function 的地址,然后每个object有一个vptr,指向virtual table所在;考虑如下代码:
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;
};
下图为Point的内存布局和其virtual table
多重继承下的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;
};

边栏推荐
- 图书馆借阅系统「建议收藏」
- Oracle库访问很慢,是什么原因?
- 什么是“安全感”?沃尔沃用它自己独特的理解以及行动来告诉你
- Report redirect after authorized login on wechat official account_ The problem of wrong URI parameters
- 【服务器数据恢复】HP StorageWorks系列存储RAID5两块盘故障离线的数据恢复案例
- Unity foundation 4 common plug-ins
- Is it necessary to disconnect all connections before deleting the PostgreSQL database?
- [complete collection of common ADB commands and their usage (from a comprehensive summary of [wake up on Sunday)]
- MoCo V1:视觉领域也能自监督啦
- Explain the mobile control implementation of unity in detail
猜你喜欢

Easynlp Chinese text and image generation model takes you to become an artist in seconds

PL515 SOT23-5 单/双口 USB 充电协议端口控制器 百盛电子代理商

Alibaba cloud MSE supports go language traffic protection

十七年运维老兵万字长文讲透优维低代码~

Seventeen year operation and maintenance veterans, ten thousand words long, speak through the code of excellent maintenance and low cost~

Unity3d tutorial notes - unity initial 03

Why on earth is it not recommended to use select *?

MobileViT:挑战MobileNet端侧霸主

LVS+KeepAlived高可用部署实战应用

全链路灰度在数据库上我们是怎么做的?
随机推荐
什么是低代码?哪些平台适合业务人员?用来开发系统靠不靠谱?
Baklib|为什么说企业需要重视客户体验?
又一款装机神器
Oracle library access is slow. Why?
C # basic 4-written examination question 1
High beam software has obtained Alibaba cloud product ecological integration certification, and is working with Alibaba cloud to build new cooperation
Thinking and summary of R & D Efficiency
JS chart scatter example
Learn about the native application management platform of rainbow cloud
LVS+KeepAlived高可用部署实战应用
mysql还有哪些自带的函数呢?别到处找了,看这个就够了。
Integrating database Ecology: using eventbridge to build CDC applications
Hangao database best practice configuration tool Hg_ BP log collection content
Unity3d tutorial notes - unity initial 02
Leetcode:2141. The longest time to run n computers at the same time [the maximum value is two points]
C # basic 1-events and commissions
Want to draw a picture that belongs to you? AI painting, you can also
微信小程序的分包加载
不懂就问,快速成为容器服务进阶玩家!
十七年运维老兵万字长文讲透优维低代码~