Why do we need “this pointer adjustor thunk”?

后端 未结 5 2025
予麋鹿
予麋鹿 2020-12-16 21:23

I read about adjustor thunk from here. Here\'s some quotation:

Now, there is only one QueryInterface method, but there are two entries, one for ea

5条回答
  •  温柔的废话
    2020-12-16 21:52

    Yes, this is essential for finding where the object start is. You write in your code:

    variable = 10;
    

    where variable is the member variable. First of all, which object does it belong to? It belongs to the object pointed to by this pointer. So it's actually

    this->variable = 10;
    

    now C++ needs to generate code that will actuall do the job - copy data. In order to do that it needs to know the offset between the object start and the member variable. The convention is that this always points onto the object start, so the offset can be constant:

    *(reinterpret_cast( reinterpret_cast( this ) + variableOffset ) ) = 10; //assuming variable is of type int
    

提交回复
热议问题