Archived

This topic is now archived and is closed to further replies.

paulkp

returning variables

Recommended Posts

Guest Anonymous Poster   
Guest Anonymous Poster
you cant return 2 variables, but you can pass the address of 2 variables and change them in the function

ex.
void func(int *v1, int *v2)
{
*v1 = 1;
*v2 = 2;
}

to call
int var1, var2;
func(&var1, &var2);

now var1 will = 1, and var2 will = 2

Share this post


Link to post
Share on other sites
Akhenaten    122
Similarly to the previous post:

void func(int &v1, int &v2)
{
v1 = 1;
v2 = 2;
}

and to call it:

int var1, var2;

func(var1, var2);

var1 will equal 1 and var2 will be 2.

Edited by - Akhenaten on June 29, 2001 10:41:43 AM

Share this post


Link to post
Share on other sites
Kylotan    9853
The C++ standard library provides a ''pair'' template:

  
pair<int, double> return_two_vars(int x)
{
return make_pair(10, 10.5);
}


(Or something like that.)

Share this post


Link to post
Share on other sites