简体   繁体   中英

C++ this->member variable how is it implemented

If I am in a member function say Hello() and I call call this->membervariable How is this implemented? Is this get the address of the this pointer and then offset to the membervariable somehow and then dereference? Keen to get some insight into the mechanics of this.

Blair

this is a pointer to the current instance of the class of which the member function belongs to. It is passed implicitly to every member function (except static functions) call you make.

this->memberVariable is like any other pointer dereference, just a shortcut for (*this).memberVariable .

对于每个成员函数,“这”是一个隐式传递的参数...由于成员函数是共享的,因此可以区分该函数针对哪个对象...记住非虚函数在编译时链接

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM