I’ve been working with references and pointers for a few months now. But what I can’t seem to find out is how to work between them and pass-by-value variables.
In the function below, I try to set the value of Icon to the UTexture2D* returned by LoadTexture.
This is because Icon is already a constructed object that was passed in (since it is passed by reference) and now you’re trying to copy the instance returned from LoadTexture() into Icon. If there is no copy assignment operator (operator ‘=’), this fails.
If you don’t want to copy the object, but instead return a pointer, do what @Hexavx suggestions.
You need to use & to get the address of an object for a pointer:
UTexture2D Icon;
UTexture2D* IconPtr = &Icon;
Trying to do *Icon goes the other way, getting the object pointed to by Icon when Icon is a pointer.
References and pointers can be confusing, especially since ‘&’ is used as both a type specifier and an address-of operator.
These are both great solutions and help me with understanding pointers and refs. I’ll apply @Hexavx 's solution
Let say for argument’s sake, I want to make a function that returns two UTexture2D or other assets passed as args. How could I make that work (if at all)?