& or no &

bool ATankPlayerController::GetSightRayHitLocation(FVector& HitLocation) const
{
	// Find the crosshair position in pixel coordinates

	int32 ViewportSizeX, ViewportSizeY;
	GetViewportSize(ViewportSizeX, ViewportSizeY);

Why do we need to use the “&” in the method signature, an not in the GetViewPortSize API method, if they are out parameters in both cases?

Is it because the int32’s where declared inside the method?

Because in this instance we are declaring/defining the function and the other we are using it.

void square(int& n)
{
    n = n * n;
}

int main()
{
    int i = 4;
    square(i); //i is now 16
    return 0;
}

So when we define like this:

bool ATankPlayerController::GetSightRayHitLocation(FVector& HitLocation) const

are we just saying that we must use an FVector called HitLocation with this method? And then we just create the variable and pass it in when we use the method?

On second thought, we wouldn’t absolutely have to call it HitLocation would we?, like when I hover over GetViewportSize I get this:

And we called the variables something a little different than SizeX or Y. So the description in the method signature is just meant to be descriptive of what the method wants?

Correct with your second thoughts. Though autocomplete would probably give you whatever is in the headers signature.

Thanks a lot man, you’re really helping me out :slight_smile:

Privacy & Terms