当前位置:网站首页>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()
}边栏推荐
- Major upgrade of openim - group chat reading diffusion model release group management function upgrade
- Transfer business append log (transaction propagation behavior)
- Do you dare to use BigDecimal without mastering these pits?
- Implementation of deep copy deepclone
- Common analog circuit design I (including simulation): mutual occurrence of square wave, triangular wave and sine wave "suggestions collection"
- Help from a student, if you can help in your spare time!
- Food safety | drinking fresh milk may infect tuberculosis? Take you to know what is milk sterilization
- 一加OnePlus 10T的一系列规格在产品发布前被披露
- Differences between nvisual generic cabling management software and network management software
- 食品安全|爱吃烟熏食品的注意了,这些知识你知道吗
猜你喜欢

Food safety | what is the origin of plant meat that sounds very healthy?

5秒到1秒,记一次效果“非常”显著的性能优化

食品安全|听起来很健康的植物肉,是什么来头?

Geometric parametric reconstruction

Thoughts on software quality system

【redis入门系列】redis的数据类型及相关命令
![[flask advanced] deeply understand the endpoint of flask routing from the source code](/img/b9/b8dd5bb8aaa1fa5580a7048b2d6ef1.png)
[flask advanced] deeply understand the endpoint of flask routing from the source code
![[operation] Yan Yi (Internet new technology operation)](/img/7a/38c7a9ed79e626506de067f360384c.png)
[operation] Yan Yi (Internet new technology operation)

Software configuration | Anaconda download, installation, environment configuration and uninstall

日志瘦身骚操作:从5G优化到1G!
随机推荐
Opencv finding the intersection of two regions
PPPoE协议讲解以及拨号过程Wireshark抓包解析
Redis分布式锁,没它真不行
[MySQL Cluster fault recovery]
WSUS can patch MySQL Middleware_ Join the WSUS patch server and download the patch
封玩家IP和机器码以及解开被封的教程
爱可可AI前沿推介(7.23)
Explain SQL optimization in detail
"Now, the number of codes has expanded to astronomical level"
乘风破浪!金融科技时代下的数字化转型之路
Can debug/release versions of dynamic library *.dll files be mixed (cross used)?
“如今,代码数已膨胀至天文级别”
Literature learning (part100) -- an introduction to autoencoders
食品安全|爱吃烟熏食品的注意了,这些知识你知道吗
Repository XXX does not have a rease file "suggested collection"
Implementation of deep copy deepclone
卷积核越大性能越强?一文解读RepLKNet模型
leetcode刷题:动态规划05(不同路径 II)
面试官:如何用 Redis 实现分布式锁?
职场3道坎:年薪30万、50万、100万