Suppose you are given the code below – will it compile?
class X { public: void someFunction (X *x) { this = x; } }
The “this” pointer can not be modified
The code above will not compile since assignment to the this parameter is not allowed in C++. The this parameter can not be modified, because it always refers to the current object. Note that trying to modify the this keyword would not work in Java either.