The Placement of & and * in relation to GunTrace and pointers in general

Just in case anyone else was confused by the declaration of member function:
bool GunTrace(FHitResult &Hit, FVector& ShotDirection)

It’s important to remember that there is no difference between:
“FVector &ShotDirection” and “FVector& ShotDirection”

You can test this by changing the position of the & in its declaration in the header vs implementation.

The following is somewhat irrelevant to this lecture but may be useful

In the scope of pointers, the & operator will always refer to the memory Address-of.
The * operator can signify both a pointer declaration AND be used as an Indirection Operator.

I don’t think the indirection operator was ever used or brought up in the series.
However, you may feel more comfortable using pointers when you understand the concepts relating to it more thoroughly.

If so, I highly suggest reading through learncpp . com or finding other resources to strengthen your understanding. If you’ve been charging through these lectures as I have, especially if you haven’t been taking notes (and you should), you’re going to get a lot of benefit by revisiting the fundamentals of C++.

Privacy & Terms