Oliver Bleckmann wrote:
hey, which ways are available i c++ to return multiple values
i know u can use structs, any other methods?
concrete question: i want to do sth. like this:
returning two strings into stringvars data and type
<data,type>=<string,stringsplittedAttribs()
strucs would lead to big changes in source...
I would recommend using tuples both for their convenience and clarity -
because unlike reference parameters, returning a tuple leaves no doubt
whether a particular value is an input or output parameter.
For example:
#include <iostream>
#include <string>
#include <tr1/tuple>
using std::tr1::tuple;
using std::tr1::make_tuple;
using std::tr1::tie;
tuple<int, char, std::stringf()
{
return make_tuple(5, 'a', "some text");
}
int main()
{
int i;
char c;
std::string s;
tie( i, c, s ) = f();
std::cout << "i: " << i << "\n";
std::cout << "c: " << c << "\n";
std::cout << "s: " << s << "\n";
}
Program Output:
i: 5
c: a
s: some text
Greg