virtual empty() const中的const有的作用
来源:互联网 发布:淘宝怎么改默认地址 编辑:程序博客网 时间:2024/05/22 03:49
后面加个const 表明该函数不会改名成员函数的值!该函数可以被常量对象访问(const)。 注意 加了const 与不加const的函数是两个不同的函数! 用个例子说明其区别:
#include <iostream> class A { public: void empty() { std::cout<<"call empty()\n"; } void empty() const { std::cout<<"call empty() const \n"; } }; void main() { const A a; //a常量对象,其只能访问常量函数 a.empty(); //访问 empty() const; 如果A中没有 empty() const 函数,编译器报错 A b; //非常量对象 b.empty(); //访问 empty() }
0 0
- virtual empty() const中的const有的作用
- C++中的Const 作用
- C++中的Const 作用
- virtual IsEmpty() const=0中的const有什么用?
- virtual IsEmpty() const=0中的const有什么用?
- const在C++中的作用
- const在C++中的作用
- const在函数中的作用
- const在c++中的作用
- const在c++中的作用(
- const 作用
- const 作用
- const作用
- const作用
- const作用
- const作用
- static const virtual 约会
- const,template,pointer,virtual
- Where is the Marble?
- HDOJ 1237 简单计算器(堆栈)
- Array.prototype.slice.call(arguments)
- HDU 4288 Coder(模拟) 附:upper_bound与lower_bound的比较
- iOS反射机制
- virtual empty() const中的const有的作用
- HDU 1272--小希的迷宫【并查集,有值得注意的地方】
- hbase 增删改查 api 简单操作
- 结构体大小计算
- UI学习笔记一 UIView和UILabel
- iOS开发分分钟搞定C语言——函数
- cocos2d3.2 渲染优化机制
- Flex HttpService请求后台获取乱码问题解决方法
- 科技论文中公式和序号怎么对齐