When should I make explicit use of the `this` pointer?

后端 未结 12 1293
甜味超标
甜味超标 2020-11-22 15:19

When should I explicitly write this->member in a method of a class?

12条回答
  •  深忆病人
    2020-11-22 15:41

    There are several reasons why you might need to use this pointer explicitly.

    • When you want to pass a reference to your object to some function.
    • When there is a locally declared object with the same name as the member object.
    • When you're trying to access members of dependent base classes.
    • Some people prefer the notation to visually disambiguate member accesses in their code.

提交回复
热议问题