Constant Member Functions
来源:互联网 发布:柳长街知乎 编辑:程序博客网 时间:2024/05/17 16:46
Declaring a member function with the const keyword specifies that the function is a "read-only"
function that does not modify for which it is called.
To declare a constant member function,place the const keyword after the closing parenthesis
of the argument list.The const keyword is requried in both the declaration and definition.A constant
member function cannot modify anydata members or call any member functions that aren't constant.
Example
//Example of a constant member function
class Date
{
public:
Date(int mn,int dy,int yr);
int getMonth() const; //A read-only function
void setMoth(int mn); //A write function;cannot be const
private:
int month;
};
int Date::getMonth() const
{
return month; //Doesn't modify anything
}
void Date::setMonth(int mn)
{
moth = mn; //Modifies data member
}
- Constant Member Functions
- Constant Member Functions
- Constant Member Functions
- Constant Member Functions
- const (Constant) Objects and const Member Functions
- Static member functions in C++
- c++: Difference between member and non member functions
- How Non-Member Functions Improve Encapsulation ZZ
- Chapter 5 Data Hiding and Member Functions
- Window Procedures as Class Member Functions
- 让 lua 调用 C++ 中的 member functions
- const member functions and const return values
- C++之虚函数(Virtual Member Functions)
- Item16 Make const member functions thread safe
- 《深度探索C++对象模型》:member functions
- Effective C++ 23. Prefer non-member non-friend functions to member functions
- 关于C++ 的constant Member function 的讲解
- 混沌 IN C++::Pointers-to-Member functions 解迷
- 用高精度方法计算n! ,并显示n!(阶乘)的值。
- Oracle操作Session的方法
- linux下后门分类
- poj 1129Channel Allocation(染色问题, DFS)
- 解决eWebEditor编辑器在火狐浏览器不能兼容的问题
- Constant Member Functions
- windows环境下MySQL数据文件目录设置
- dom学习备忘
- 在排序数组中寻找两个数使其和等于给定数
- HtmlEditor问题总结
- MyEclipse6.5安装SVN插件的三种方法
- TextView一直显示跑马灯效果
- Nginx配置中运行与启动的详细介绍
- Serial Peripheral Interface Bus · Motorola SPI ARM PL022 控制器驱动移植 SPI接口的SD卡调试