Should I use `this` within a class?

2019-01-11 18:15发布

Within a member function of a class in C++, does it make a difference, if I use this->dataMember or just dataMember? What is considered better style? Is there any performance difference?

(I am not talking about the case where a local variable has the same name as the data member, in which case you must, to my knowledge, use this-> to distinguish between them.)

标签: c++ class this
7条回答
闹够了就滚
2楼-- · 2019-01-11 19:01

If a template function makes a call to a member function such that the call does not depend on any template parameters, this-> can be used to help the compiler as an alternative to MyUtopicClass<int, double, double>::vin().

查看更多
登录 后发表回答