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_ = ;
value_ = ;
} private:
int id_;
mutable int value_;
}; int _tmain(int argc, _TCHAR* argv[])
{
TestMutable test;
test.love(); return ;
}
id_ = 11; 这句编译时将会报错。 testmultable.cpp(11) : error C2166: l-value specifies const object
value_ = 12; 可以通过, mutable 关键字指定value_是易变的。
 

mutable c++的更多相关文章

  1. [LeetCode] Range Sum Query 2D - Mutable 二维区域和检索 - 可变

    Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper lef ...

  2. [LeetCode] Range Sum Query - Mutable 区域和检索 - 可变

    Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...

  3. volatile关键字和mutable关键字

    如果不用volatile关键字会如何?可能会造成一个后果就是:编译器发现你多次使用同一个变量的值,然后它可能会假设这个变量是不变的值,并且把这个变量的值放入寄存器中,方便下一次使用,提高存取速度. 一 ...

  4. explicit,violate,volatile,mutable小结

    转自:http://blog.csdn.net/helonsy/article/details/7091130 explicit:放在构造函数前面可以阻止构造函数的隐式类型转换.这样可以避免不必要的错 ...

  5. Range Sum Query 2D - Mutable & Immutable

    Range Sum Query 2D - Mutable Given a 2D matrix matrix, find the sum of the elements inside the recta ...

  6. 三种线程不安全现象描述(escaped state以及hidden mutable state)

    hidden mutable state和escaped state是两种线程不安全问题:两者原因不同,前者主要是由于类成员变量中含有其他对象的引用,而这个引用是immutable的:后者是成员方法的 ...

  7. LeetCode Range Sum Query 2D - Mutable

    原题链接在这里:https://leetcode.com/problems/range-sum-query-2d-mutable/ 题目: Given a 2D matrix matrix, find ...

  8. spark1.5 scala.collection.mutable.WrappedArray$ofRef cannot be cast to ...解决办法

    下面是我在spark user list的求助贴,很快就得到了正确回答,有遇到问题的同学解决不了也可以去上面提问. I can use it under spark1.4.1,but error on ...

  9. C++ const、volatile、mutable的用法 (转)

      const.volatile.mutable的用法 鸣谢作者: http://blog.csdn.net/wuliming_sc/article/details/3717017 const修饰普通 ...

  10. Swift开发第五篇——四个知识点(Struct Mutable方法&Tuple&autoclosure&Optional Chain)

    本篇分三部分: 一.Struct Mutable方法 二.多元组(Tuple) 的使用 三.autoclosure 的使用 四.Optional Chain 的使用 一.Struct Mutable方 ...

随机推荐

  1. python-daemon

    http://legacy.python.org/dev/peps/pep-3143/#python-daemon install yum install python-daemon example ...

  2. Django QuestSet API (官方文档)

    1.返回新查询集的方法 (1)filter():滤指定条件的结果 Entry.objects.filter(pub_date__gt=datetime.date(2005, 1, 3), headli ...

  3. cesium 显示视角高度以及鼠标经纬度

    HTML中的内容 <div id="cesiumContainer"> <!-- 设置经纬度显示 --> <span style="font ...

  4. TeXstudio安装后提示no LaTeX distribution found on this system

    应该是设置一下用户变量,而非系统变量,用TeXLive 2015和MikTeX都不好使,最后设置了用户变量好使了 S:\TeX\MiKTeX 2.9\miktex\bin\x64\ 也是醉醉的 不过等 ...

  5. [转载]——Axure+SVN配置

    最近进行考试系统重构,一个小组十几个人,这么多人要同时搞需求画原型.这样原本的合作开发工具SVN已经不能满足现在的需求了,这是就找到了一个新的方法——Axure+SVN. 在SVN服务器端建立一个空的 ...

  6. 【转】你是不是也被Android Private Libraries、Referenced Libraries、android Dependency搞晕了~~

    一.v4.v7.v13的作用和用法 1.Android Support V4, V7, V13是什么? 本质上就是三个java library. 2.为什么要有support库?   是为了解决软件的 ...

  7. css3阴影 box-shadow

    语法 box-shadow:X轴偏移量 y轴偏移量 [阴影模糊半径] [阴影扩展半径] [阴影颜色] [投影方式] 参数介绍: 注:inset 可以写在参数的第一个或最后一个,其它位置是无效的. 阴影 ...

  8. phpmyadmin高级功能尚未完全设置部分功能未激活

    1.登录phpmyadmin,点击导入,选择/var/ww/html/phpmyadmin/examples/create_tables.sql并执行 完成后可以看到多出了一个库phpmyadmin. ...

  9. Kettle报表自动化

    来自我们牛逼哄哄的东哥的笔记 1.   2. 3. 选择数据库链接 贴报表SQL 4. 文件名:选择路径,excel文件由kettle自动创建,自己只需输入创建文件的名称. 拓展名:后缀写上 5. 此 ...

  10. 修改与遍历MAP

    package com.*; import java.util.*; /** * Created by HP on 2018/8/2. */ public class Test { //定义一个用于转 ...