Change 'this' pointer of an object to point different object

后端 未结 6 1375
花落未央
花落未央 2021-02-07 08:01
class C{
   //methods and properties
}

void C::some_method(C* b){
    delete this;
    this = b;     
}

This gives me follwing error when compiling:

6条回答
  •  无人及你
    2021-02-07 08:47

    The error says "You can't assign b to this". As far as I know, this is something you can't change, because it's not an actual pointer, but a self-reference.

提交回复
热议问题