Is there a preferred way to return multiple values from a C++ function? For example, imagine a function that divides two integers and returns both the quotient and the rema
There is precedent for returning structures in the C (and hence C++) standard with the div
, ldiv
(and, in C99, lldiv
) functions from
(or
).
The 'mix of return value and return parameters' is usually the least clean.
Having a function return a status and return data via return parameters is sensible in C; it is less obviously sensible in C++ where you could use exceptions to relay failure information instead.
If there are more than two return values, then a structure-like mechanism is probably best.