10 years, 1 month ago.

Command "this->"

Hi, could somebody explain me what does the command "this->" I can´t find it on the internet thanks for help

1 Answer

10 years, 1 month ago.

I thought googling it as "this->" would return results, but I was wrong :D.

'this' is the pointer to the current object of a class. Since it is a pointer, you need to use the arrow to access functions/variables belonging to the pointer. If you for example have a class with a function "randomFunction()", then from another function in the same class you can execute that function with this->randomFunction();

Now I don't know if you have some experience with classes, but if you have you probably know you can also just execute that same function without the "this->" part. However sometimes there is some ambiguity, with several variables/functions with the same name. In that case using "this->" you clearly define it needs to execute the function/access the variable belonging to the class.

Here it is further explained: http://www.learncpp.com/cpp-tutorial/87-the-hidden-this-pointer/

Accepted Answer