const函数的使用
const知道吗?解释其作用。
1.const 修饰类的成员变量,表示成员常量,不能被修改。
2.const修饰函数承诺在本函数内部不会修改类内的数据成员,不会调用其它非 const 成员函数。
3.如果 const 构成函数重载,const 对象只能调用 const 函数,非 const 对象优先调用非 const 函数。
4.const 函数只能调用 const 函数。非 const 函数可以调用 const 函数。
5.类体外定义的 const 成员函数,在定义和声明处都需要 const 修饰符
6.const在*的左边,则指针指向的变量的值,不可直接通过指针改变(可以通过其他途径改变);
在*的右边,则指针的指向不可变。简记为“左定值,右定向”。
const函数的使用的更多相关文章
- c++ const函数是什么意思
c++ const函数是什么意思 只读类型 const修饰在类的成员函数的尾部,表示这个函数不会修改类的成员.相当于this指针是const的.
- stl::map之const函数访问
如何在const成员数中访问stl::map呢?例如如下代码: string ConfigFileManager::MapQueryItem(const string& name) const ...
- (转)Const,Const函数,Const变量,函数后面的Const
本文转自http://www.cnblogs.com/Fancyboy2004/archive/2008/12/23/1360810.html 看到const 关键字,C++程序员首先想到的可能是co ...
- const参数,const返回值与const函数
在C++程序中,经常用const 来限制对一个对象的操作,例如,将一个变量定义为const 的: const int n=3; 则这个变量的值不能被修改,即不能对变量赋值. const 这个关键字 ...
- const和非const函数重载
成员函数后面加const,表示在该函数中不能对类的数据成员进行改变,比如下面的代码: #include <stdio.h> class A { private: mutable int a ...
- [EffectiveC++]item03:尽可能使用const 并且转载一篇关于const函数的博客
速度 #include <iostream> using namespace std; class TextBlock { private: string text; public: Te ...
- 两种const函数
有两种const函数,声明如下:1.const T func();2.T func() const;第一种表示返回的是const的类型,也即返回的值不能作为左值,楼主懂的.第二种表示该成员函数不能修改 ...
- const函数返回自身的引用也是常量引用
const函数返回自身的引用也是const 解决:根据对象是否为consr重载
- C++中如何可以修改const函数内的成员变量的值?
呵呵,你使用mutable关键字来定义变量就可以了.下面举例说明 C++关键字mutable Mutable (1)mutable的意思是"可变的,易变的",跟C++中的const ...
随机推荐
- atof和atoi
atof:将字串转换成浮点型数 表头文件 #include <stdlib.h> 函数说明 atof()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,而 ...
- linux下svn的建库以及相关配置
1.安装svn软件 yum install subversion -y 2.建立库的根目录,此目录下为所有库的根目录(路径为:/home/svn-server/) ,然后进入此目录 mkdir /ho ...
- STS和Eclipse安装Lombok插件
参考:https://www.cnblogs.com/caozx/p/9510354.html 参考:https://blog.csdn.net/wutian90/article/details/87 ...
- EasyUI设置Layout自适应浏览器宽度和高度
//设置自适应浏览器宽度和高度 function setLayoutHeight() { var height = $(window).height() - 20; $("#main_lay ...
- 解决error while loading shared libraries
ldd print shared library dependencies.可以查看哪些库没有找到. 这个进程启动失败,使用ldd命令可以发现是因为memcache库没有发现.把该so文件放入/lib ...
- April Fools Contest 2017 A
Description Input The input contains a single integer a (1 ≤ a ≤ 30). Output Output a single integer ...
- BFS Codeforces Round #297 (Div. 2) D. Arthur and Walls
题目传送门 /* 题意:问最少替换'*'为'.',使得'.'连通的都是矩形 BFS:搜索想法很奇妙,先把'.'的入队,然后对于每个'.'八个方向寻找 在2*2的方格里,若只有一个是'*',那么它一定要 ...
- K-th Number 线段树的区间第K大
http://poj.org/problem?id=2104 由于这题的时间限制不紧,所以用线段树水一水. 每个节点保存的是一个数组. 就是对应区间排好序的数组. 建树的时间复杂度需要nlogn 然后 ...
- MySQL执行带out的存储过程
CALL `sp_sys_get_code`(3,'sys_customer',@code); SELECT @code
- 动手实现 React-redux(四):mapDispatchToProps
在重构 ThemeSwitch 的时候我们发现,ThemeSwitch 除了需要 store 里面的数据以外,还需要 store 来 dispatch: ... // dispatch action ...