Doubt in the class

Can you tell me why this-> has been used. We could have rather assigned the value directly in x in the function.

hello @vageesha

no we cant direcly assign x (the local variable ) to x (the member variable)

compiler will not be able to distinquish both of them .

if u write
x=x (then compiler just assing value of local x in the same variable)

so to distinguish the variables with same name we are using this operator.

this ->x (means we are talking about member variable) and normal x means we are talking about local variable.
thats why bhaiya wrote
this->x=x

read more about this operator from internet

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.