Why we are not using this->car_name like this->x and this->y at 5:35 of video?
This pointer use
Hey @nemishgarg1999
Works either ways. You can write this->car_name or car_name, it’s gonna work fine. But it’s important to write this->x = x, x = x won’t work, this is required to differentiate. Similarly for y.
Thanks @mahimahans111
Can you tell me more about why
this->x = x;
is always required as compared to
x = x;
@nemishgarg1999
Here when the class member and the variable name which is assigned to the member is same, this keyword has to be used in the constructor to assign value to the class member.
In the statement
this->x = x
The ‘this’ pointer is used to retrieve the object’s x hidden by the local variable ‘x’. The x on the LHS written with this, thus denotes the class member and the x on the RHS denotes the variable whose value is assigned to the class member
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.