return values from function

Apr 21, 2012 at 2:17pm
I want to return two arrays from a function. How can I achieve this?
Thank you~
Apr 21, 2012 at 2:45pm
One of these, perhaps:
1
2
3
4
5
std::pair< std::vector<int>, std::vector<double> > foo() ;

std::vector<int> bar( std::vector<double>& result2 ) ;

void baz( std::vector<int>& result1, std::vector<double>& result2 ) ;

Apr 21, 2012 at 3:05pm
I cannot understand the last two, can you explain them? thanks!
Apr 21, 2012 at 4:37pm
> I cannot understand the last two, can you explain them?

std::vector<int> bar( std::vector<double>& result2 ) ;
returns a vector<int> and sets the values in the vector<bouble> which is passed by reference.

In void baz( std::vector<int>& result1, std::vector<double>& result2 ) ;, both sequences are passed by reference.

See: http://www.learncpp.com/cpp-tutorial/73-passing-arguments-by-reference/

Last edited on Apr 21, 2012 at 4:37pm
Apr 21, 2012 at 5:14pm
We could give a better answer if you were more specific about what you are trying to do, exactly. Can you post some code that demonstrates what you want? (The code doesn't have to work, obviously -- it just has to show us what you are trying to do.)
Topic archived. No new replies allowed.