最新下载
热门教程
- 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成员函数。
相关文章
- 口袋斗罗大陆小舞有哪些玩法技巧 09-16
- 逆战未来冰狙击步枪如何组装 09-16
- 如鸢董奉角色怎么样 09-16
- 环外技能怎么进阶 09-16
- 三国群英传策定九州如何发展建筑 09-16
- 三国望神州郭嘉怎么玩 09-16