The this
pointer [ class.this ] で、C++ 標準は次のように述べています。
this
クラスのメンバ関数のの型X
は ですX*
。
すなわちthis
ありませんconst
。しかし、なぜそれはそれである
struct M {
M() { this = new M; }
};
与える
error: invalid lvalue in assignment <-- gcc
'=' : left operand must be l-value <-- VC++
'=' : left operand must be l-value <-- clang++
'=' : left operand must be l-value <-- ICC
(source: some online compiler frontends)
言い換えれば、そうでthis
はありませんconst
が、実際にはそうです!