当前位置:网站首页>Const decorated member function problem
Const decorated member function problem
2022-07-06 10:11:00 【anieoo】
C++ When defining class objects in this The pointer , Point to the object itself defined by the class .
this General purpose of pointer :
When a parameter has the same name as a member variable , You can use this Pointer to distinguish
Return the object itself in the class's non static member function , You can use return* this
When I try to modify this When the pointer points to , Find out vs Prompt error :
Found after review this The essence of a pointer is a pointer constant , The point of the pointer is not modifiable , namely :Person* const this;
however this The data of the object the pointer points to can be modified .
If you want the value pointed to by the pointer, you can't change , Statement is required Constant function . That is, in function const modification :
As you can see from the diagram const Modifying Member Functions , Data representing the memory space pointed to by the pointer cannot be modified . The function of this constant function is actually to this The pointer is added const Embellishment becomes const Type* const this; therefore this Neither the direction nor the value of the direction can be modified !!!!
however C++ Provides a way to modify in constant functions this The data of the memory space pointed to by the pointer , The box mutable Keywords modify variables .
Similar to constant functions are Constant variable .
utilize const Class name Variable name , Define constant variable . As you can see from the diagram Constant variables can only access the value of member variables , But it can't be modified , But it can be modified mutable key word Modified member variables .
As can be seen from the above figure , Constant variables can only call constant functions , Ordinary member functions cannot be called !!!
边栏推荐
- Southwest University: Hu hang - Analysis on learning behavior and learning effect
- Several errors encountered when installing opencv
- 美疾控中心:美国李斯特菌疫情暴发与冰激凌产品有关
- CAPL脚本中关于相对路径/绝对路径操作的几个傻傻分不清的内置函数
- 宝塔的安装和flask项目部署
- C杂讲 文件 续讲
- Listen to my advice and learn according to this embedded curriculum content and curriculum system
- [untitled]
- Random notes
- CANoe下载地址以及CAN Demo 16的下载与激活,并附录所有CANoe软件版本
猜你喜欢
15 医疗挂号系统_【预约挂号】
History of object recognition
MySQL实战优化高手04 借着更新语句在InnoDB存储引擎中的执行流程,聊聊binlog是什么?
[flask] crud addition and query operation of data
How can I take a shortcut to learn C language in college
max-flow min-cut
Single chip microcomputer realizes modular programming: Thinking + example + system tutorial (the degree of practicality is appalling)
MySQL实战优化高手11 从数据的增删改开始讲起,回顾一下Buffer Pool在数据库里的地位
C miscellaneous dynamic linked list operation
Combined search /dfs solution - leetcode daily question - number of 1020 enclaves
随机推荐
If someone asks you about the consistency of database cache, send this article directly to him
PR 2021 quick start tutorial, first understanding the Premiere Pro working interface
MySQL实战优化高手05 生产经验:真实生产环境下的数据库机器配置如何规划?
C杂讲 文件 初讲
South China Technology stack cnn+bilstm+attention
Carolyn Rosé博士的社交互通演讲记录
Programmation défensive en langage C dans le développement intégré
MySQL实战优化高手09 生产经验:如何为生产环境中的数据库部署监控系统?
[untitled]
AI的路线和资源
CANoe下载地址以及CAN Demo 16的下载与激活,并附录所有CANoe软件版本
17 medical registration system_ [wechat Payment]
If a university wants to choose to study automation, what books can it read in advance?
Safety notes
13 medical registration system_ [wechat login]
CAPL script pair High level operation of INI configuration file
Canoe CAPL file operation directory collection
16 medical registration system_ [order by appointment]
Which is the better prospect for mechanical engineer or Electrical Engineer?
[one click] it only takes 30s to build a blog with one click - QT graphical tool