【发布时间】:2011-06-12 06:29:55
【问题描述】:
可能的重复:
Is there any reason to use this->
When should this-> be used?
When should I make explicit use of thethispointer?
当使用指向类的指针时,我喜欢在类中的变量前面添加一个this->,以便更清楚地表明我正在谈论的变量是在当前类中,而不是临时变量等. 所以我的台词会是这样的
if(this->thing > other->thing)
this->doFoo();
代替
if(thing > other->thing)
doFoo();
可以添加多余的this,还是会降低代码的可读性?
【问题讨论】:
-
这真的是一个判断电话,除非是为了消除歧义。我认为大多数 C++ 程序员都忽略了
this->。
标签: c++ class pointers this this-pointer