当前位置:网站首页>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 !!!
边栏推荐
- 解决在window中远程连接Linux下的MySQL
- CAPL script pair High level operation of INI configuration file
- 简单解决phpjm加密问题 免费phpjm解密工具
- Defensive C language programming in embedded development
- C杂讲 双向循环链表
- Canoe CAPL file operation directory collection
- 颜值爆表,推荐两款JSON可视化工具,配合Swagger使用真香
- Installation of pagoda and deployment of flask project
- Constants and pointers
- CANoe CAPL文件操作目录合集
猜你喜欢

C miscellaneous dynamic linked list operation

Hugo blog graphical writing tool -- QT practice
![[CV] target detection: derivation of common terms and map evaluation indicators](/img/e8/04cc8336223c0ab2dea5638def88df.jpg)
[CV] target detection: derivation of common terms and map evaluation indicators

History of object recognition

CANoe不能自动识别串口号?那就封装个DLL让它必须行

Some thoughts on the study of 51 single chip microcomputer

Routes and resources of AI

13 医疗挂号系统_【 微信登录】

MySQL实战优化高手11 从数据的增删改开始讲起,回顾一下Buffer Pool在数据库里的地位

PR 2021 quick start tutorial, first understanding the Premiere Pro working interface
随机推荐
Several errors encountered when installing opencv
Constants and pointers
Preliminary introduction to C miscellaneous lecture document
Safety notes
MySQL real battle optimization expert 08 production experience: how to observe the machine performance 360 degrees without dead angle in the process of database pressure test?
MySQL實戰優化高手04 借著更新語句在InnoDB存儲引擎中的執行流程,聊聊binlog是什麼?
MySQL实战优化高手09 生产经验:如何为生产环境中的数据库部署监控系统?
软件测试工程师必备之软技能:结构化思维
在CANoe中通過Panel面板控制Test Module 運行(初級)
Configure system environment variables through bat script
MySQL实战优化高手02 为了执行SQL语句,你知道MySQL用了什么样的架构设计吗?
13 医疗挂号系统_【 微信登录】
Some thoughts on the study of 51 single chip microcomputer
Tianmu MVC audit II
16 medical registration system_ [order by appointment]
宝塔的安装和flask项目部署
Contrôle de l'exécution du module d'essai par panneau dans Canoe (primaire)
How does the single chip microcomputer execute the main function from power on reset?
cmooc互联网+教育
Sichuan cloud education and double teacher model