c++ Mutable
来源:互联网 发布:易语言盗号源码2016 编辑:程序博客网 时间:2024/06/06 03:33
(1)mutable的意思是“可变的,易变的”,跟C++中的const是反义词。
(2)在C++中,mutable也是为了突破const的限制而设置的。被mutable修饰的变量,将永远处于可变的状态,即使在一个const函数中
实例说明:
#include <iostream>using namespace std;class TestMutable{public: TestMutable(){i=0;} int Output() const { return i++; //error C2166: l-value specifies const object }private: int i;};int main(){ TestMutable testMutable; cout<<testMutable.Output()<<endl; return 0;}
显然i++在const修饰的函数里是编译通不过的。
#include <iostream>using namespace std;class TestMutable{public: TestMutable(){i=0;} int Output() const { return i++; }private: mutable int i;};int main(){ TestMutable testMutable; cout<<testMutable.Output()<<endl; return 0;}
在 int i 前面加上 mutable上面就能编译通过了,马上可以看出关键字mutable的作用了。
原文链接:http://www.cnblogs.com/chenyuming507950417/archive/2012/01/05/2313647.html
0 0
- C++'s mutable
- 关键字 mutable (c++)
- C++'s mutable
- 关键字 mutable (c++)
- 关键字 mutable (c++)
- 关键字 mutable (c++)
- 关键字 mutable (c++)
- 关键字 mutable (c++)
- 关键字mutable(C++)使用
- 关键字 mutable (c++)
- c++关键字mutable
- c++关键字mutable
- 【c++】static、const、mutable关键词
- mutable
- mutable
- mutable
- mutable
- mutable
- 9: Command Line Arguments(Command line Python scripting)
- 浅谈 PHP 与手机 APP 开发(API 接口开发)
- 在SecureCRT中向linux上传和下载文件
- uva753(一般图匹配)
- NSDate NSDateFormatter 转化格式
- c++ Mutable
- error: command 'gcc' failed with exit status when installing psycopg2
- C++ Built-in Operators, Precedence and Associativity
- android开发桌面控件之液晶时钟
- 通俗的解释进程和线程
- Hololens 学习摘要及翻译记录 二 World coordinates
- Android学习日记(yzy):集成布局和滑动效果的实现
- 图片格式转换
- android 相对布局属性