C++ 一些小的知识点
2017-07-10 09:55
253 查看
很久不接触C++了,工作需要,很多东西都忘记了,只好把一些细小的知识点记录在这里帮助自己记忆。
Declaring a member function with the const keyword specifies that the function is a "read-only" function that does not modify the object 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 required in both the declaration and the definition. A constant member function cannot modify any data members or call any member functions that aren't constant.
从上面的说明来看,constant member function 有两个方面,一是它不能改变对象的非const数据成员,也不能调用对象的非const方法。二是,它可以改变对象的const数据成员[注意const数据成员本来是不可以改变的],可以调用对象的const方法。
1、const放在最后,表示此成员函数不改变类中的成员变量。
2、const放在函数参数中,表示此参数在函数体不会被改变。
3、const放在最前,表示返回const值
Declaring a member function with the const keyword specifies that the function is a "read-only" function that does not modify the object 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 required in both the declaration and the definition. A constant member function cannot modify any data members or call any member functions that aren't constant.
从上面的说明来看,constant member function 有两个方面,一是它不能改变对象的非const数据成员,也不能调用对象的非const方法。二是,它可以改变对象的const数据成员[注意const数据成员本来是不可以改变的],可以调用对象的const方法。
1、const放在最后,表示此成员函数不改变类中的成员变量。
2、const放在函数参数中,表示此参数在函数体不会被改变。
3、const放在最前,表示返回const值
相关文章推荐
- c++模板的一些知识点总结
- C++中有关的复合类型变量的知识点的一些见解
- 关于C/C++一些面试/笔试题的反思(超基础的知识点)
- c++的一些知识点
- c/c++的一些小知识点3
- c/c++一些容易遗忘的知识点(不断补充)
- C++一些容易忽略的知识点
- 收集的一些c++知识点与题目一
- 【c++ 一些比较细节的知识点】函数指针
- C/C++的一些知识点归纳(一)
- C/C++一些易混淆的知识点
- 【C++再学习】【05】有关类的一些知识点整理
- C++的一些知识点汇总
- 关于C/C++一些面试/笔试题的反思(超基础的知识点)
- 关于C++的一些小知识点
- C/C++ 一些被忽视却又很重要的知识点
- C++的一些小知识点
- C++的一些知识点总结
- c/c++一些小知识点(特此总结)
- C/C++的一些知识点归纳(二)