+ 8
What is the concept of '->' and 'this' ?
2 ответов
+ 3
-> is used to access to memory address of one pointer through another
while this is an instance, like object of the class
+ 2
-> is used in lieu of: (*ptr).
For example: (*ptr1).ptr2 == ptr1->ptr2
'this' is a pointer that points to the object of a given class and can be used when an object is referring to itself.
This website has a great example: https://www.tutorialspoint.com/cplusplus/cpp_this_pointer.htm
Here you see the definition of the function int compare(Box box) using 'this.' If you had a box object (box1) and compared it to another box (box2), you'd use 'this' to refer to the volume member variable of box1 when calling compare. Like saying, "Compare the volume of THIS box (box1) to the other box (box2).