Hello! I followed this tutorial about C++ programming: "3rd Person Power-Up Game with C++". I just don't understand why I should use pointers when I create a class type variable like in the "Pickup.h"
Can't I just use like this?
And if not, why?
asked Apr 12 '16 at 02:25 PM in C++ Programming
You use pointers because Unreal has a garbage collector. Unreal will sense when the PickupMesh is created / destroyed and take actions accordingly. It is the same reason that you spawn an actor instead of creating one with new. Unreal's garbage collection is highly efficient so you need not worry. Also from a memory perspective, having a pointer to an external class ( this is called assosciation), has less overhead than creating a member variable. For eg : let's say you a class like this :
Now, B has a pointer so it's data will be 4 bytes in size. But suppose if you change the class to the following:
Now B has an int and a float ( 8 bytes of data). This is just an example of a primitive class, imagine how much memory you would occupy when the class has huge data.
Follow this question
Once you sign in you will be able to subscribe for any updates here