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

后端 未结 5 1133
臣服心动
臣服心动 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:53

    Your class can have custom operator& (so &a may not return this of a). That's why std::addressof exists.

提交回复
热议问题