当前位置:网站首页>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 !!!
边栏推荐
- 在CANoe中通过Panel面板控制Test Module 运行(初级)
- vscode 常用的指令
- MySQL实战优化高手11 从数据的增删改开始讲起,回顾一下Buffer Pool在数据库里的地位
- Automation sequences of canoe simulation functions
- Redis集群方案应该怎么做?都有哪些方案?
- [CV] target detection: derivation of common terms and map evaluation indicators
- oracle sys_ Context() function
- MySQL实战优化高手02 为了执行SQL语句,你知道MySQL用了什么样的架构设计吗?
- Routes and resources of AI
- C杂讲 文件 续讲
猜你喜欢
Several silly built-in functions about relative path / absolute path operation in CAPL script
16 医疗挂号系统_【预约下单】
在CANoe中通過Panel面板控制Test Module 運行(初級)
Release of the sample chapter of "uncover the secrets of asp.net core 6 framework" [200 pages /5 chapters]
Which is the better prospect for mechanical engineer or Electrical Engineer?
Installation of pagoda and deployment of flask project
Automation sequences of canoe simulation functions
PR 2021 quick start tutorial, first understanding the Premiere Pro working interface
Embedded development is much more difficult than MCU? Talk about SCM and embedded development and design experience
在CANoe中通过Panel面板控制Test Module 运行(高级)
随机推荐
17 medical registration system_ [wechat Payment]
Combined search /dfs solution - leetcode daily question - number of 1020 enclaves
cmooc互联网+教育
How to make shell script executable
C杂讲 动态链表操作 再讲
MySQL combat optimization expert 05 production experience: how to plan the database machine configuration in the real production environment?
VH6501学习系列文章
MySQL real battle optimization expert 11 starts with the addition, deletion and modification of data. Review the status of buffer pool in the database
C杂讲 浅拷贝 与 深拷贝
MySQL实战优化高手02 为了执行SQL语句,你知道MySQL用了什么样的架构设计吗?
Simple solution to phpjm encryption problem free phpjm decryption tool
Canoe cannot automatically identify serial port number? Then encapsulate a DLL so that it must work
flask运维脚本(长时间运行)
Random notes
MySQL实战优化高手11 从数据的增删改开始讲起,回顾一下Buffer Pool在数据库里的地位
History of object recognition
在CANoe中通过Panel面板控制Test Module 运行(高级)
The 32 year old programmer left and was admitted by pinduoduo and foreign enterprises. After drying out his annual salary, he sighed: it's hard to choose
MySQL的存储引擎
If someone asks you about the consistency of database cache, send this article directly to him