Why the hell would anyone do this-> unless they had to?
There maybe a big debate and argument, or flame war on this.
But here is three reasons why I prefix this->
1,
class A {
public:
void print(std::string message);
void useIt() {
this->print("what"); // safe
printf("what"); // should call print, but a typo, and compiles and runs OK.
}
};
2,
class A {
public:
void funcA(int someValue) {
someValue *= 2;
this->myAnotherValue = someValue;
}
void funcB(int someValue) {
someValue *= 2;
myAnotherValue = someValue;
}
}
When reading the code, for funcB, I need another 1 or 2 seconds to think "oh, myAnotherValue is member, someValue is parameter, etc". For funcA, I don't need the 1 or 2 seconds. And for funcB I maybe not know if myAnotherValue is a member, a global, or a magic macro, if it's third party code.
OK, typing this-> may need 1 second, but I only need to type once, and will read many time.
3, Sometime it's forced to use this->. Such like value assignment with same name, in some templates. then why not just keep consistent.