Suppose I have a class like:
Class MyClass
{
int myVar1;
int myVar2;
void myMethod();
}
is there any difference in the two value assignments below ?
void MyClass::myMethod()
{
//VARIABLE ASSIGNMENT
myVar1 = 99;
//USING POINTER TO CLASS
this->myVar2 = 99;
}
What’s the use of the
this->
pointer in variables’ assignment (except other cases when eg. passing the class via a function etc.) ?
It’s the same thing, unless you happen to have two variables with the same name in the scope. In that case you can differentiate using this->.