C++ parameter is also return value?

Hi,

as a Java programmer, I have problems understanding how it works that the following two lines of code actually update currentMousePos_ with the new mouse position? :

FVector2D currentMousePos_;
GEngine->GameViewport->GetMousePosition(currentMousePos_);

And is it then better to create a FVector2D pointer variable and only pass the adress of currentMousePos_ to the function?
How does the above work performance wise?

Hey, thanks for your answer,
I also originally was using

currentMousePos_ = GEngine->GameViewport->GetMousePosition();

but the engine told me to change this, because it is marked as deprecated.

What I don’t understand about your answer: I thought you pass by reference using the & sign?

Regarding passing by reference. As the function GetMousePosition(&FVector2D MousePosition) already has as a parameter, the reference of a FVector2D you don’t need to supply the input to the function with your own reference to the variable. As it’s already denoted as one and will be treated as one, without having the & sign.

~Per “Gimmic” Johansson

As an aside, normally functions whose parameters are actually return values (as in this case) the parameter is named OutSensibleName to indicate the value is filled in by the function (as per the Unreal Engine coding standard).