当前位置:网站首页>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;
};

边栏推荐
- 上市1个月接连发生两起安全事故,理想L9还理想吗?
- Unity - script lifecycle
- 智能家居行业发展,密切关注边缘计算和小程序容器技术
- 什么是低代码?哪些平台适合业务人员?用来开发系统靠不靠谱?
- Tested interviewed Zuckerberg: reveal more details of four VR prototypes
- Unity foundation 1 - event execution sequence, custom events
- C foundation 8-reflection and dependency injection
- 怎样搭建企业内部维基百科
- DeiT:注意力Attention也能蒸馏
- Moco V3: visual self supervision ushers in transformer
猜你喜欢

What functions does MySQL have? Don't look everywhere. Just look at this.

取色器实战(Qt含源码)

Moco V1: the visual field can also be self supervised

Unity foundation 2 editor expansion

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

Guo Mingxuan: meta contraction is conducive to the development of VR competitors, and apple XR headshow will change the industry rules
Looking at SQL optimization from the whole process of one query

How to modify the ID of NetApp expansion enclosure disk shelf

MobileViT:挑战MobileNet端侧霸主

Eureka registers with each other, only showing each other or only showing problems in one
随机推荐
DeiT:注意力Attention也能蒸馏
ctfshow 做题 web模块 web11~web14
C foundation 8-reflection and dependency injection
一名在读研究生的自白:我为什么会沉迷于openGauss 社区?
DLL decompile (decompile encrypted DLL)
MySQL sorts out the review content -- with mind map
The EMC vnx5200 fault light is on, but there is no hardware fault prompt
unity-shader-1
BUUCTF做题Upload-Labs记录pass-11~pass-20
Unity - Fundamentals of 3D mathematics
向往的开源之多YOUNG新生 | 从开源到就业的避坑指南来啦!
Baklib | why do enterprises need to pay attention to customer experience?
Nacos 原理
Unity3d tutorial notes - unity initial 04
Job CE
Young freshmen yearn for more open source | here comes the escape guide from open source to employment!
怎样搭建企业内部维基百科
Interpretation of ue4.25 slate source code
Cause analysis of restart of EMC cx4-120 SPB controller
The average altitude is 4000 meters! We built a cloud on the roof of the world