当前位置:网站首页>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 !!!
边栏推荐
- Safety notes
- Several silly built-in functions about relative path / absolute path operation in CAPL script
- Constants and pointers
- CANoe下载地址以及CAN Demo 16的下载与激活,并附录所有CANoe软件版本
- CANoe CAPL文件操作目录合集
- NLP路线和资源
- jar运行报错no main manifest attribute
- 软件测试工程师发展规划路线
- MySQL實戰優化高手04 借著更新語句在InnoDB存儲引擎中的執行流程,聊聊binlog是什麼?
- MySQL combat optimization expert 07 production experience: how to conduct 360 degree dead angle pressure test on the database in the production environment?
猜你喜欢
C杂讲 双向循环链表
A necessary soft skill for Software Test Engineers: structured thinking
Redis集群方案应该怎么做?都有哪些方案?
C miscellaneous shallow copy and deep copy
实现微信公众号H5消息推送的超级详细步骤
Learning SCM is of great help to society
MySQL实战优化高手03 用一次数据更新流程,初步了解InnoDB存储引擎的架构设计
MySQL实战优化高手12 Buffer Pool这个内存数据结构到底长个什么样子?
C miscellaneous two-way circular linked list
Use xtrabackup for MySQL database physical backup
随机推荐
Why is 51+ assembly in college SCM class? Why not come directly to STM32
16 医疗挂号系统_【预约下单】
通过bat脚本配置系统环境变量
Why can't TN-C use 2p circuit breaker?
软件测试工程师必备之软技能:结构化思维
15 医疗挂号系统_【预约挂号】
Contest3145 - the 37th game of 2021 freshman individual training match_ C: Tour guide
The appearance is popular. Two JSON visualization tools are recommended for use with swagger. It's really fragrant
Tianmu MVC audit II
Teach you how to write the first MCU program hand in hand
软件测试工程师必备之软技能:结构化思维
The replay block of canoe still needs to be combined with CAPL script to make it clear
C杂讲 浅拷贝 与 深拷贝
[one click] it only takes 30s to build a blog with one click - QT graphical tool
Embedded development is much more difficult than MCU? Talk about SCM and embedded development and design experience
MySQL实战优化高手02 为了执行SQL语句,你知道MySQL用了什么样的架构设计吗?
A new understanding of RMAN retention policy recovery window
[CV] target detection: derivation of common terms and map evaluation indicators
在CANoe中通过Panel面板控制Test Module 运行(高级)
竞赛vscode配置指南