当前位置:网站首页>Debug:形参带有Const修饰符号需要注意的地方
Debug:形参带有Const修饰符号需要注意的地方
2022-07-23 15:00:00 【本菜;】
有一段代码
class Animal{
public:
void Print(){
std::cout<<"this is Animal"<<std::endl;
}
}
void My_Print(const Animal& animal){
animal.Print()
}这样会报错,因为我们的Animal变量是加了Const标记的,而我们的Print函数是没有加标记的,这说明我们可以通过Print进行修改,而这与Cons标记相违背,所以我们不能在Const类实例中调用非Const方法,这里做以下修改就行:
class Animal{
public:
void Print() const{
std::cout<<"this is Animal"<<std::endl;
}
}
void My_Print(const Animal& animal){
animal.Print()
}边栏推荐
- Scene notes
- Pymoo learning (3): use multi-objective optimization to find the set of optimal solutions
- sns_sensor_instance_api
- The difference between try catch and if else statements in PHP
- Detailed explanation of SQL bool blind note and time blind note
- Encapsulate the general connection and query of the project with pymysql
- LQR 控制学习-LQR控制 MATLAB官方教程-LQR 控制器_状态空间系统Matlab/Simulink建模分析
- Detailed explanation of SQL error reporting and blind annotation
- 12张图+6K字图解ZGC垃圾回收器及调优技巧
- [JS] check whether the date object is invalid date
猜你喜欢

Pymoo learning (3): use multi-objective optimization to find the set of optimal solutions

Kubernetes kubelet hard core knowledge architecture

isEmpty 和 isBlank 的用法区别,至少一半的人答不上来...

Food safety | attention to smoking food, do you know this knowledge

Food safety chocolate is also true or false? How much do you know about it

Aike AI frontier promotion (7.23)

程序员最想干的三件事 |漫画

分析optimism重放合约地址攻击事件

ride the wind and waves! Digital transformation in the era of financial technology

Three things programmers want to do most | comics
随机推荐
12 pictures +6k figure ZGC garbage collector and tuning skills
Kubernetes kubelet hard core knowledge architecture
Pymoo learning (3): use multi-objective optimization to find the set of optimal solutions
职场3道坎:年薪30万、50万、100万
KV260单板PS控制设置IIC开关芯片
Major upgrade of openim - group chat reading diffusion model release group management function upgrade
来自某学生的求助,干了,闲暇能帮就帮一把!
Program environment and pretreatment
Food safety | what is the origin of plant meat that sounds very healthy?
记录一下MySql update会锁定哪些范围的数据
【redis入门系列】redis的数据类型及相关命令
Deeply understand the mode and vibration of mechanical system
PPPoE协议讲解以及拨号过程Wireshark抓包解析
日志瘦身骚操作:从5G优化到1G!
Emgu cv3+c # image processing (IV): use emgucv to obtain camera and read video
USB通信协议深入理解
深入理解机械系统的模态与振动
Software configuration | Anaconda download, installation, environment configuration and uninstall
别再问我MySQL为啥没走索引?就这几种原因,全都告诉你
isEmpty 和 isBlank 的用法区别,至少一半的人答不上来...