当前位置:网站首页>Lesson 24 analysis of classical problems
Lesson 24 analysis of classical problems
2022-04-23 12:05:00 【Night rain】
Lesson 24 Analysis of classical problems ( Construction and deconstruction sequence )
List of articles
One 、 Problem analysis
-
problem : When there are multiple objects in a program , How to determine the deconstruction order of these objects ?
The order in which constructors are called when a single object is created
-
Call the construction process of the parent class
-
Call the constructor of a member variable ( Call order is the same as declaration order )
A class contains other classes , The calling order is in the order of declaration
-
Call the constructor of the class itself
The destructor is called in the reverse order of the corresponding constructor
-
Be careful : The above three are not independent , But called in this order
For stack objects and global objects , It is similar to the order of entering and leaving the stack , The last constructed object first destructs
Destructions of heap objects occur when delete When , And delete The order of use of
-
-
problem :const Keyword can modify the object of the class ? If possible , what are you having? 1 characteristic ?
const Keywords can decorate objects
const The decorated object is a read-only object
Member variables of read-only objects are not allowed to be changed
System object is the concept of compilation stage , Invalid runtime
C++ Medium const Member functions
-
const Object can only call const Member function of
-
const Only... Can be called in member functions const Member functions
-
const The value of a member variable cannot be overwritten directly in a member function
-
const Member function definition :
type calssname::function(type p) const
Be careful :
const It's in the back
The function declaration in the class and the function definition in the historical records must contain const keyword
-
-
problem : Do member functions and member variables belong to specific objects ?
From the perspective of object oriented
- Object by property ( Member variables ) And methods ( Member functions ) constitute
From the perspective of program operation
- Objects consist of data and functions , Data can be on the heap 、 Stack 、 And global data area , Functions can only be in code snippets
So all objects share a set of member functions , Because member functions cannot be deleted
Conclusion
- Each object has its own independent properties ( Member variables )
- Methods of all objects sharing classes ( Member functions )
- Method can directly access the properties of an object
- Method this Used to refer to the current object
There is only one set of member functions , Member functions can access member variables in any class
Two 、 Summary
- The destruct order of objects is opposite to the construction order
- const Keywords can decorate objects , Get a read-only object
- Read only objects can only be called const Member functions
- All objects share the member functions of the class
- Hidden this Pointer is used to represent the current object
版权声明
本文为[Night rain]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231155356044.html
边栏推荐
- Tensorflow uses keras to create neural networks
- Golang's pen test questions & interview questions 01
- The database navigator uses the default MySQL connection prompt: the server time zone value 'Ö Ð¹ ú±ê ×¼ ʱ ¼ ä’ is unrecognized or repres
- Optimize connections using connection groups (IM 6)
- 亿级流量架构,服务器如何扩容?写得太好了!
- Docker MySQL master-slave backup
- AI 视频云 VS 窄带高清,谁是视频时代的宠儿
- Im architecture: CPU architecture: SIMD vector processing (im-2.3)
- 第四章 为IM 启用填充对象之启用和禁用表空间的IM列存储(IM 4.5)
- Tan Xiang, CEO of Kechuang · Pera software: the essence of zero trust is digital security. To B should also deeply study the user's mind
猜你喜欢
Docker MySQL master-slave backup
IFLYTEK's revenue in 2021 was 18.3 billion yuan: a year-on-year increase of 41% and a net profit of 1.556 billion yuan
欣旺达宣布电池产品涨价 此前获“蔚小理”投资超10亿
IDEA设置版权信息
Next. JS static data generation and server-side rendering
怎么进行固定资产盘点,资产盘点报告如何一键生成
VMware虚拟机使用esxi 导出硬盘vmdk文件
Nativeformysql connects to MySQL 8 prompt: 1251 - client does not support authentication protocol
CGC: contractual graph clustering for community detection and tracking
Fastjson 2 来了,性能继续提升,还能再战十年
随机推荐
Idea database navigator plug-in
Design and practice of the smallest short website system in the whole network
Castle.DynamicProxy实现事务单元控制
golang之笔试题&面试题01
论文解读(CGC)《CGC: Contrastive Graph Clustering for Community Detection and Tracking》
Share two practical shell scripts
第四章 为IM 启用填充对象之启用和禁用表空间的IM列存储(IM 4.5)
The fourth chapter is the enable and disable columns of IM enabled fill objects (Part III of im-4.3)
Docker MySQL master-slave backup
论文解读(CGC)《CGC: Contrastive Graph Clustering for Community Detection and Tracking》
初探 Lambda Powertools TypeScript
Sofa weekly | excellent Committee of the year, contributor of this week, QA of this week
远程桌面之终端服务器超出了最大允许连接数解决
Nacos Basics (5): getting started with Nacos configuration
对称加密、证书加密
Here comes the detailed picture and text installation tutorial of H5 game
Solution of asynchronous clock metastability -- multi bit signal
远程访问家里的树莓派(上)
Precautions for PCB
Fabric 1.0 source code analysis (33) implementation of peer channel command and subcommand