Difference between -> and

What is the difference between -> and . and when to use each ?

This is a more advance topic if you are not really familiar with programming but I’ll try to summarize it and point you in the right direction.

The quick answer is -> is a Pointer to an object, and . means you already have an instance of the object.

Ben or Sam had a great analogie for it. So a pointer is basically a reference to an object store somewhere. It points toward the adresse of the object. So when you do ->, you say follow the adresse and you’ll get the object. As of when you have an instance, you already have the object.

Pointer are useful because that way, multiple pointer can point to the same object in memory. And therefore, it can be modified from different places.

Hope it helped you! I’ll leave a couple of link here and don’t hesitate if you need more clarification, this is one of the hardest concept to grasp in C++!

https://wiki.unrealengine.com/Entry_Level_Guide_to_UE4_C%2B%2B#Pointers
http://www.cplusplus.com/doc/tutorial/pointers/
https://www.ntu.edu.sg/home/ehchua/programming/cpp/cp4_PointerReference.html

thanks alot Carl

Privacy & Terms