在C++重载运算符时"const"是什么意思
what does "const" mean when overloading operator in C++
我看到了这样的内容:
const char& operator[] (int Index) const
我理解的第一个const
。这是为了保护返回的char
不被修改。
但是第二个const
是什么意思?为什么我们有时用两个const
,有时只用一个?
可用于任何成员函数,而不仅仅是操作符。这意味着,这个函数将:
- 不能修改任何数据成员(
mutable
除外) - 将无法调用任何非
const
成员函数
相关文章:
- "char const * name() const _WEBSOCKETPP_NOEXCEPT_TOKEN_ {"剂量是什么意思
- 语法问题:"char [5] const &"是什么意思?
- 这个(const vector<vector<int> > &A)"代码段是什么意思?
- classname functionname(const classname & objectname)是什么意思?
- "const char(&a)[N]"是什么意思?
- "inline operator T*() const"是什么意思?
- const 在具有尾随返回类型的自动退货声明中是什么意思
- :void setData(const Color * & data_ptr)中的 *& 是什么意思;
- 成员函数限定符(const除外)是什么意思
- const K& k = K() 在这个构造函数中是什么意思?
- T const & 在函数的返回类型中是什么意思?
- 过载"operator X*() const"是什么意思?
- const 在不同地方的 C++ 中是什么意思
- const T& value() const 是什么意思?
- 这C++代码是什么意思?'const ResTable&res = am->getResources();'
- 这是什么意思?:注意:参数 1 没有从"int"到"const 帐户"的已知转换
- 函数头后面的const是什么意思
- 当 const 放在函数的声明之后是什么意思?
- const T*const是什么意思
- "const name{something}"是什么意思?