Skip to main content
GameDev.net gamedev.net
🔒 Locked

Quick Question -- Howdo i get a function to return multiple values

Started by MrPoopypants Dec 6, 2002 at 7:13 PM 1 replies 450+ views
Original Post
MrPoopypants
MrPoopypants
(C++)
    
int GenerateRandomOblio ( int a , int b , int c , int d )
{
	srand ( time( 0 ) );
	
	do
	{
	a = rand() % 9 + 1;
	b = rand() % 9 + 1;
	c = rand() % 9 + 1;
	d = rand() % 9 + 1;
	}
	while( a != b && a != c && a != d && b != c && b != d && c != d );



	return (a , b , c , d);
}
    
When i run this program and cout the value, it displays only a. (What i am trying to do is return four integers != to one another) Any help would be appreciated. thanks [edited by - MrPoopypants on December 6, 2002 8:20:03 PM]
(0110101101000110)The Murphy Philosophy: Smile . . . tomorrow will be worse.
randomDecay
randomDecay
You can only return one value from a function.

However, you can return a pointer to something. IE -- a pointer a to a structure.

Also, you can pass those integers as pointers to the function and then you can modify those so that when you return from the function, a, b, c, and d are modified to reflect what you did with them in the function (I think this is what you want to do).

[edited by - randomDecay on December 6, 2002 8:21:37 PM]
sjelkjd
sjelkjd

  
struct ret_value
{
int a,b,c,d;
};
ret_value myfunc()
{
...
}

or
pair<pair<int,int>,pair<int,int> > myfunc()
{
return make_pair(make_pair(a,b),make_pair(c,d));
}

or even better, check out boost::tuple

edit: code vs source tags

[edited by - sjelkjd on December 6, 2002 8:34:15 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.