# C++ parameter is also return value?

**URL:** <https://forums.unrealengine.com/t/c-parameter-is-also-return-value/324404>\
**Category:** Editor Scripting\
**Tags:** return, reference, parameter, unreal-engine, UE4, CPP, question\
**Created:** [July 7, 2015, 5:18pm UTC](https://forums.unrealengine.com/t/c-parameter-is-also-return-value/324404 "2015-07-07T17:18:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_68436a09](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_68436a09](https://forums.unrealengine.com/u/anonymous_user_68436a09)\
**Post date:** [July 7, 2015, 5:18pm UTC](https://forums.unrealengine.com/t/c-parameter-is-also-return-value/324404/1 "2015-07-07T17:18:08Z")

</div>

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_);

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_68436a09](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_68436a09](https://forums.unrealengine.com/u/anonymous_user_68436a09)\
**Post date:** [July 7, 2015, 5:20pm UTC](https://forums.unrealengine.com/t/c-parameter-is-also-return-value/324404/2 "2015-07-07T17:20:54Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_68436a09](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_68436a09](https://forums.unrealengine.com/u/anonymous_user_68436a09)\
**Post date:** [July 8, 2015, 8:51am UTC](https://forums.unrealengine.com/t/c-parameter-is-also-return-value/324404/3 "2015-07-08T08:51:28Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Coder\_Gimmic](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/coder_gimmic/32/467009_2.png) [@Coder\_Gimmic](https://forums.unrealengine.com/u/Coder_Gimmic)\
**Post date:** [July 8, 2015, 10:24am UTC](https://forums.unrealengine.com/t/c-parameter-is-also-return-value/324404/4 "2015-07-08T10:24:09Z")

</div>

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_

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2db7ca80](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2db7ca80](https://forums.unrealengine.com/u/anonymous_user_2db7ca80)\
**Post date:** [July 8, 2015, 11:52am UTC](https://forums.unrealengine.com/t/c-parameter-is-also-return-value/324404/5 "2015-07-08T11:52:38Z")

</div>

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](https://docs.unrealengine.com/latest/INT/Programming/Development/CodingStandard/index.html#namingconventions)).
