What is the concept of '->' and 'this' ? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 8

What is the concept of '->' and 'this' ?

27th Jun 2017, 12:26 AM
Jugnu
Jugnu - avatar
2 ответов
+ 3
-> is used to access to memory address of one pointer through another while this is an instance, like object of the class
27th Jun 2017, 1:06 AM
Nura Programmer
Nura Programmer - avatar
+ 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).
27th Jun 2017, 1:20 AM
Joseph P French
Joseph P French - avatar