在指针[ class.thisthis ] 中,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,但它确实是!