mutable关键字
生活随笔
收集整理的這篇文章主要介紹了
mutable关键字
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
? ? ? ??mutable是為了突破const限制,即使是const函數(shù),也能對mutable變量進行修改。
include <iostream>using namespace std;class test { public:test(){a = 0;}void addA() const {a++;cout<< "a=" << a << endl;}private:mutable int a;};int main() {test t;t.addA();return 0; }編譯運行,打印:a=1
總結(jié)
以上是生活随笔為你收集整理的mutable关键字的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: muduo之channel
- 下一篇: c++ try...catch异常处理