最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
C++ 中const对象与const成员函数的实例详解
时间:2022-06-25 04:35:02 编辑:袖梨 来源:一聚教程网
const对象只能调用const成员函数:
#includeusingnamespacestd; classA { public: voidfun()const { cout<<"const 成员函数!"<
输出:const 成员函数!
但是如果把第以1个fun注释掉就会出错:error C2662: “A::fun”: 不能将“this”指针从“const A”转换为“A &”。
但是const成员函数可以被非const 对象调用:
#includeusingnamespacestd; classA { public: voidfun()const { cout<<"const 成员函数!"<
该段代码输出:const 成员函数!
当然非const对象可以调用非const成员函数。
相关文章
- 《异界事务所》光谱项链哪几种 06-30
- 《雾境序列》波比角色大全全解析 06-30
- 《星球重启》SSR宠物盲盒免费怎么获得 06-30
- 操作教程:常见的NFT被盗手段?为什么NFT玩家成为黑客目标? 06-30
- 拳皇97风云再起出招表-拳皇97风云再起技能招式表一览 06-30
- 鸣潮坎特蕾拉培养攻略-鸣潮坎特蕾拉培养材料一览 06-30