作者dedicationsh (ddd)
看板C_and_CPP
标题[问题] 关於const的问题
时间Tue Feb 23 00:58:04 2016
开发平台(Platform): (Ex: VC++, GCC, Linux, ...)
VC++
额外使用到的函数库(Library Used): (Ex: OpenGL, ...)
no
问题(Question):
class Time {
public:
const Time operator+(const Time &) const;
(1) (2) (3)
…
};
请问第(3)个const是代表什麽意思?
第(1)个const应该是指回传的Time是不可以被修改
第(2)则是说 输入的 Time reference不能被修改
那第(3)是代表什麽呢?
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.114.200.75
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1456160288.A.E09.html
※ 编辑: dedicationsh (140.114.200.75), 02/23/2016 01:01:20
1F:推 CoNsTaR: 代表成员函式不会动到资料成员 02/23 01:06
2F:→ CoNsTaR: 第一个 const 是没用的吧 02/23 01:07
3F:推 LPH66: 可以把它想成是 this 的常数性 02/23 01:10
4F:→ LPH66: 平常的 this 是 T * const, 即我可以透过指标更改物件内容 02/23 01:10
5F:→ LPH66: 加了那个 const 则表示那个成员函式里面的 this 是 02/23 01:11
6F:→ LPH66: const T * const, 也就是连透过指标都不能改动 02/23 01:11
7F:推 littleshan: 第一个const会导致回传值无法成为rvalue reference 02/23 01:33
8F:→ Caesar08: 第一个const,在没有move前(C++03)是有用的 02/23 10:13
9F:推 Yshuan: pure function? 02/23 18:29