Difference between 'this->' and calling directly?

If I call a function from within its own class, I can use either `this->` or I can just call it directly.

For example, using `this->Test(true)` generates the same result as `Test(true)`.

Is there any difference between the two?
If so, what are the advantages and disadvantages of using each?
They are the same.

The only time it might make a difference to use the "this->" prefix is to resolve a name/scope conflict.

Personally I avoid using this-> because it's unnecessarily verbose and code-cluttering.
closed account (z05DSL3A)
on the other hand which one gives the reader more information about the code they are reading?

this->Test(true)
Test(true)
@Grey Wolf
That's true, if we had two `Test(bool var)` functions (one inside the class and the other outside), the `this->Test(true)` would give us information that the one inside the class is being called.

I can also see it helping in debugging.
I like the this->Test(true); form better too. I always do it that way, although I always feel guilty about it and dumb, because one time years ago I read somewhere that its a 'mark of beginners', and the gurus don't do it. So be it I guess.
Using this-> is inconsistent. You're basically explicitly specifying the scope you want when you do it, so why are you not doing that everywhere else in your program too? Additionally, it doesn't solve the problem you think it does - this-> can also allow you to access inherited members.
closed account (z05DSL3A)
LB wrote:
You're basically explicitly specifying the scope you want when you do it, so why are you not doing that everywhere else in your program too?
How do you know I don't explicitly specify scope?

To me the most important thing is to get the most information out of the least amount of code reading when I am maintaining it months after I last read it.

Topic archived. No new replies allowed.