void f() const 常成员函数
来源:互联网 发布:京东大数据平台架构 编辑:程序博客网 时间:2024/06/05 02:40
const修饰类的成员函数,则该成员函数不能修改类中任何非const成员函数,也不能修改任何成员变量。一般写在函数的最后来修饰。
如:
class A {… void function()const; //常成员函数, 它不改变对象的成员变量. //也不能调用类中任何非const成员函数。}
对于const类对象/指针/引用,只能调用类的const成员函数,因此,const修饰成员函数的最重要作用就是限制对于const对象的使用。
如果在编写const成员函数时,不慎修改了数据成员,或者调用了其他非const成员函数,编译器将报错,提高了程序的健壮性。
void f() const makes the function itself const. This only really has meaning for member functions. Making a member function const means that it cannot call any non-const member functions, nor can it change any member variables. It also means that the function can be called via a const object of the class.
0 0
- void f() const 常成员函数
- const用法之常对象,常成员函数,常引用
- void const f() vs void f() const
- const 修饰的常函数成员
- C++常成员函数 - const 关键字
- C++常成员函数 - const 关键字
- C++常成员函数 - const 关键字
- C++常成员函数 - const 关键字
- 常成员函数:Const类限定的成员函数
- 常成员const
- 常对象 常成员函数
- 常引用,常对象,常成员函数,常数据成员~
- C++ 常对象成员、常成员函数
- 常对象成员和常成员函数
- 常成员:常数据成员和常成员函数
- 常成员函数
- 常成员函数
- 常成员函数
- Response 弹出js代码的方法
- nginx的proxy_pass和 location为正则表达式的问题
- Tomcat+MySQL的配置(windows下)
- python入门学习
- Mysql常用的几种SQL提示
- void f() const 常成员函数
- eclipse插件
- 有关“CRT detect that the application wrote to memory after end of heap buffer”问题的解决
- Sql Server 取出多个字段列中的最大值和最小值
- eclipse 导出可运行jar包 cmd命令执行java **.jar时找不到第三方jar包问题
- hdu 1081 最大子矩阵求和问题
- cocos2d-x 2.2.2 android win7平台环境配置
- 初识HTML
- Python中zip()函数用法举例