function that returns two values?

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Clodi
Posts: 175
Joined: November 18th, 2012, 7:47 pm

function that returns two values?

Post by Clodi » October 13th, 2014, 9:01 pm

Hello,
I have

Code: Select all

int position[3];
I can then have a set function:

Code: Select all

void setPosition( int,int,int );
what about a get function that returns all three integer's?
:D

cameron
Posts: 794
Joined: June 26th, 2012, 5:38 pm
Location: USA

Re: function that returns two values?

Post by cameron » October 13th, 2014, 9:15 pm

Return a struct/class object.
Computer too slow? Consider running a VM on your toaster.

Clodi
Posts: 175
Joined: November 18th, 2012, 7:47 pm

Re: function that returns two values?

Post by Clodi » October 13th, 2014, 9:18 pm

thanks mate!
for that simple example you would obviously use a struct right? (not a class)

cameron
Posts: 794
Joined: June 26th, 2012, 5:38 pm
Location: USA

Re: function that returns two values?

Post by cameron » October 13th, 2014, 9:27 pm

Depends, but I would probably do struct.
Computer too slow? Consider running a VM on your toaster.

Clodi
Posts: 175
Joined: November 18th, 2012, 7:47 pm

Re: function that returns two values?

Post by Clodi » October 13th, 2014, 9:35 pm

cheers mate

Xydrel
Posts: 2
Joined: October 14th, 2014, 2:34 am

Re: function that returns two values?

Post by Xydrel » October 14th, 2014, 2:38 am

Another option, if your compiler has support for C++11, you can set and return a Tuple. That's a multi value object.

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: function that returns two values?

Post by albinopapa » October 14th, 2014, 7:24 pm

Why would anyone use tuple's over structs?
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Post Reply