当前位置:网站首页>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 !!!
边栏推荐
- AI的路线和资源
- [after reading the series] how to realize app automation without programming (automatically start Kwai APP)
- Target detection -- yolov2 paper intensive reading
- [Julia] exit notes - Serial
- Vscode common instructions
- 在CANoe中通过Panel面板控制Test Module 运行(高级)
- 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?
- cmooc互联网+教育
- 安装OpenCV时遇到的几种错误
- How to make shell script executable
猜你喜欢
C miscellaneous two-way circular linked list
History of object recognition
C杂讲 文件 初讲
Which is the better prospect for mechanical engineer or Electrical Engineer?
嵌入式開發中的防禦性C語言編程
CANoe不能自动识别串口号?那就封装个DLL让它必须行
MySQL combat optimization expert 03 uses a data update process to preliminarily understand the architecture design of InnoDB storage engine
How to make shell script executable
Mexican SQL manual injection vulnerability test (mongodb database) problem solution
Contest3145 - the 37th game of 2021 freshman individual training match_ C: Tour guide
随机推荐
CANoe仿真功能之自动化序列(Automation Sequences )
17 医疗挂号系统_【微信支付】
美新泽西州州长签署七项提高枪支安全的法案
13 medical registration system_ [wechat login]
Vh6501 Learning Series
MySQL combat optimization expert 09 production experience: how to deploy a monitoring system for a database in a production environment?
西南大学:胡航-关于学习行为和学习效果分析
16 medical registration system_ [order by appointment]
15 医疗挂号系统_【预约挂号】
Implement context manager through with
[NLP] bert4vec: a sentence vector generation tool based on pre training
Programmation défensive en langage C dans le développement intégré
Vscode common instructions
Sichuan cloud education and double teacher model
Competition vscode Configuration Guide
How to make shell script executable
Mexican SQL manual injection vulnerability test (mongodb database) problem solution
MySQL Real Time Optimization Master 04 discute de ce qu'est binlog en mettant à jour le processus d'exécution des déclarations dans le moteur de stockage InnoDB.
MySQL实战优化高手03 用一次数据更新流程,初步了解InnoDB存储引擎的架构设计
MySQL实战优化高手02 为了执行SQL语句,你知道MySQL用了什么样的架构设计吗?