最新下载
热门教程
- 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成员函数。
相关文章
- 原神虹色大巡回第五天怎么玩 05-10
- hbar币交易所官方网站2024 05-10
- gopay钱包app下载官网2024手机版 05-10
- topay钱包官网app 05-10
- Filecoin钱包app下载最新版 05-10
- Huobi钱包app官网版 05-10