Download

Is it ok to use out parameters in a void function?

is this a valid way of writing functions?

void GetCameraParameters(float& TP_FOV, float& FP_FOV, bool& RightShoulder);

Yes, it is the only way to return several types except if using a struct or class.

Yes you can absolutely do this.
Consider renaming your function. Out parameters are not return values, so you don’t really “get” anything. Just based on your function signature and parameter names, I’m guessing this function is more intended to calculate the values of your out params.

I could be wrong and this is a minor nitpick but there’s a good reason to keep your code as self documenting as possible.

This is not recommended.
Cons:

  • even if caller don’t modify these variables, you cannot make them const.
  • increases the scope of the variable (must be defined and initialized before calling the function)
  • less obvious than a regular return from a function

Out-parameters are mainly used when it has a significant impact, e.g. on performance (mainly applies to types that use dynamic allocation like FString orTArray.

A good example is the std::getline from STL.

void some_function(std::istream & file)
{
   std::string buffer;
   while (std::getline(file, buffer)) {
     process(buffer);
   }
}

Instead of creating a new string each time (+ allocate memory) one object is used and reallocation takes place only when needed.