In a function, how to you assign this
a new value?
Long ago, before the first C++ standard has been published, some compiler implementations allowed you to write the following code inside a constructor:
this = malloc(sizeof(MyClass)); // <<== No longer allowed
The technique served as the only way to control allocation of class of objects. This practice has been prohibited by the standard, because overloading of the operator new
has solved the problem that used to be tackled by assignments to this
.