A C++ function can return only one value. However, you can return multiple values by wrapping them in a class or struct.
struct Foo
{
int value1;
int value2;
};
Foo SomeFunction()
{
Foo result = { 5, 4 };
return result;
}
Or you could use std::tuple
, if that is available with your compiler.
#include <tuple>
std::tuple<int, int, int> SomeFunction()
{
return std::make_tuple(5, 4, 3);
}
If you don't know in advance how many values you're going to return, a std::vector
or a similar container is your best bet.
You can also return multiple values by having pointer or reference arguments to your function and modifying them in your function, but I think returning a compound type is generally speaking a "cleaner" approach.