Does this pointer not a lvalue reference? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

Does this pointer not a lvalue reference?

Hi We cannot modify this pointer inside a member function something like below : void changePtr(T* p) { this = p; } Is it something c++ has not allowed to change pointer? Any specific reason for blocking the behaviour?

10th Aug 2020, 3:08 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
2 Réponses
+ 2
Yeah true... I don't have use case and it's not something I gonna do also..this is one of the question in Sololearn challenge and make me think why it has been set as rvalue
10th Aug 2020, 5:49 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
We have const specifier for member function... Function argument can be set as const by keyword before data type... Member function const means this pointer is aslo const... Does this not enough to block one making someone change this pointer ? Is it necessary to have it as rvalue ?
10th Aug 2020, 5:17 PM
Ketan Lalcheta
Ketan Lalcheta - avatar