Can 'this' pointer be different than the object's pointer?

后端 未结 5 1129
臣服心动
臣服心动 2021-02-05 11:28

I\'ve recently came across this strange function in some class:

void* getThis() {return this;}

And later in the code it is sometimes used like

5条回答
  •  花落未央
    2021-02-05 11:36

    I ran across something like this many (many many) years ago. If I recall correctly, it was needed when a class is manipulating other instances of the same class. One example might be a container class that can contain its own type/(class?).

提交回复
热议问题