C++成员函数末尾const关键字…
来源:互联网 发布:南风知我意 书包网 编辑:程序博客网 时间:2024/06/05 05:17
1>
我们假设调用语句为obj.foo(),如果obj为non-const对象,则调用foo()。如果obj为const对象,则调用foo()const。另外要注意,假如没有提供foo()const,则constobj调用foo()将会报错。但假如是没有提供foo(),则non-constobj调用foo()const是完全没有问题的。也就是说,non-const对象可以调用const函数,但const对象不能调用non-const函数:-)
2>const关键字所起作用的本质,就是把隐藏着的默认的this指针参数,改成const类型。也就是说:
假如void
这样做有两个效果,第一:编译器将不允许foo()const修改pThis指向的对象的成员。第二、const对象只能调用const成员函数,否则就会报错说把constT* 转化为T* 会丢失qualifier
----------------------------------
Only member functions declaredas
class Screen
{
public:
bool isEqual( char ch ) const; // ...private:
string::size_type _cursor;
string _screen; // ...
};
bool Screen::isEqual( char ch ) const
{
return ch == _screen[_cursor];
}
- C++成员函数末尾const关键字…
- 成员函数末尾使用const关键字
- C++成员函数末尾const关键字的作用
- 含有const关键字成员函数
- const关键字类成员函数
- c++const成员函数
- const成员函数和mutable关键字
- C++ Const关键字修饰变量、成员函数!
- C++ Const关键字修饰变量、成员函数!
- C++常成员函数 - const 关键字
- C++常成员函数 - const 关键字
- C++常成员函数 - const 关键字
- C++常成员函数 - const 关键字
- const成员函数、inline成员函数、static成员函数中关键字的位置
- 高质量c++(const成员函数)
- 高质量c++(const成员函数)
- 高质量c++(const成员函数)
- 高质量c++(const成员函数)
- Linux性能分析工具——top
- Linux 离线安装 gcc g++
- Linux性能分析工具——mpstat
- 什么是scatter / gather
- Mongodb shard 索引
- C++成员函数末尾const关键字…
- Fedora 设置第三方软件原
- linux mongodb driver&n…
- python中调用dos命令
- Linux 下好用的QQ
- 简单卷、跨区卷、带区卷、镜像卷和…
- 正则表达式
- RSS技巧
- keytool 不是内部或外部命令