zoukankan      html  css  js  c++  java
  • mutable c++

      The keyword mutable is used to allow a particular data member of const object to be modified. This is particularly useful if most of the members should be constant but a few need to be updateable. 

    Test:

    #include "stdafx.h"
    
    class TestMutable
    {
    public:
        void love() const
        {
            id_ = 11;
            value_ = 12;
        }
    
    private:
        int id_;
         mutable int value_;
    };
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        TestMutable test;
        test.love();
    
        return 0;
    }
    id_ = 11; 这句编译时将会报错。 testmultable.cpp(11) : error C2166: l-value specifies const object
    value_ = 12; 可以通过, mutable 关键字指定value_是易变的。
     
  • 相关阅读:
    Linux命令:ssh
    Linux命令:sshpass
    Linux命令:ls
    Linux文件的时间
    Linux命令:findutils
    jfrog
    git
    git branch
    git remote
    java equals 和hashcode
  • 原文地址:https://www.cnblogs.com/iclk/p/3685678.html
Copyright © 2011-2022 走看看