+ 4

When to use . operator and when to use -> operator ?

. is direct access operator -> is indirect access operator Can anyone explain , please?

10th Dec 2017, 6:43 AM
Hrishikesh Kulkarni
Hrishikesh Kulkarni - avatar
3 odpowiedzi
+ 15
The target. dot works on objects; arrow works on pointers to objects. std::string str("foo"); std::string * pstr = new std::string("foo"); str.size (); pstr->size (); The . operator is for direct member access. object.Field The arrow dereferences a pointer so you can access the object/memory it is pointing to pClass->Field https://stackoverflow.com/questions/11902791/what-is-the-difference-between-and-in-c
10th Dec 2017, 6:50 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 32
http://www.cplusplus.com/forum/beginner/139181/ The (.) dot and The (->) arrow operator. - C++ Forum - Cplusplus.com
10th Dec 2017, 6:50 AM
Nithiwat
Nithiwat - avatar
+ 5
Thank you very much Nithiwat and GAWEN STEASY
10th Dec 2017, 6:53 AM
Hrishikesh Kulkarni
Hrishikesh Kulkarni - avatar