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_ = ;
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++的更多相关文章
- [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 ...
- [LeetCode] Range Sum Query - Mutable 区域和检索 - 可变
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...
- volatile关键字和mutable关键字
如果不用volatile关键字会如何?可能会造成一个后果就是:编译器发现你多次使用同一个变量的值,然后它可能会假设这个变量是不变的值,并且把这个变量的值放入寄存器中,方便下一次使用,提高存取速度. 一 ...
- explicit,violate,volatile,mutable小结
转自:http://blog.csdn.net/helonsy/article/details/7091130 explicit:放在构造函数前面可以阻止构造函数的隐式类型转换.这样可以避免不必要的错 ...
- 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 ...
- 三种线程不安全现象描述(escaped state以及hidden mutable state)
hidden mutable state和escaped state是两种线程不安全问题:两者原因不同,前者主要是由于类成员变量中含有其他对象的引用,而这个引用是immutable的:后者是成员方法的 ...
- LeetCode Range Sum Query 2D - Mutable
原题链接在这里:https://leetcode.com/problems/range-sum-query-2d-mutable/ 题目: Given a 2D matrix matrix, find ...
- 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 ...
- C++ const、volatile、mutable的用法 (转)
const.volatile.mutable的用法 鸣谢作者: http://blog.csdn.net/wuliming_sc/article/details/3717017 const修饰普通 ...
- Swift开发第五篇——四个知识点(Struct Mutable方法&Tuple&autoclosure&Optional Chain)
本篇分三部分: 一.Struct Mutable方法 二.多元组(Tuple) 的使用 三.autoclosure 的使用 四.Optional Chain 的使用 一.Struct Mutable方 ...
随机推荐
- python 输出奇偶数并排序
random_numbers = [] for i in range(40): random_numbers.append(random.randint(1, 100)) num1 = [] num2 ...
- HTML5开发,背后的事情你知道吗?
现在的H5越来越受到企业或者是开发者的一个大力的追捧,已经成为网络推广必不可少的一个使用的工具,相信还有很多朋友现在都不知道H5是个什么东西,本文将为大家讲的是关于H5一些分类的问题,让你进一步的去学 ...
- win8下使用IIS服务器及自定义服务器端包含模块(SSI)步骤
配置完过段时间就容易忘记,特此记录. 1.开启IIS服务器. 默认没有安装,需要先安装. 打开控制面板--> 打开“程序和功能”--> 左侧选择“启用或关闭windows功能”--> ...
- 深搜,四色定理,(POJ1129)
题目链接:http://poj.org/problem?id=1129 解题报告: #include<iostream> #include<cstdio> #include&l ...
- Flash Media Live Encoder参数表
Flash Media Live Encoder命令行推流Flash Media Live Encoder NotesFlash Media Live Encoder 除了直接以 GUI 方式操作之外 ...
- this指针和类的继承
神秘的家伙 在对象的世界里,有一个特殊的指针,它叫做this.我们从来没有见过他,但是他却从来都存在.我们通过一个典型的例子来认识它: class Human { char fishc; Human( ...
- [P1363] 幻想迷宫
题目链接 很好的一道搜索题,应该是利用了离散化的思想我好蒟蒻呀 地图是根据给定的图无限的拼接的. 所以说暴力建图是不可取的. 其实不难看出,在跨越两张图时.我们就可以看做这个点时空穿梭一般.从底下回来 ...
- C#程序设计入门经典之C#的基本语法
C#代码的外观和操作方式与C++和Java非常类似.初看起来,其语法可能比较混乱,不像书面英语和其他语言.但是,在C#编程中,使用的样式是比较清晰的,不用花太多的力气就可以编写出可读性很强的代码. 与 ...
- caffe中的sgd,与激活函数(activation function)
caffe中activation function的形式,直接决定了其训练速度以及SGD的求解. 在caffe中,不同的activation function对应的sgd的方式是不同的,因此,在配置文 ...
- iconv for linux(c)
// code_convert("gb2312","utf-8",inbuf,outbuf,outlen);static int code_convert(co ...