Page 1 of 1

function that returns two values?

Posted: October 13th, 2014, 9:01 pm
by Clodi
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

Re: function that returns two values?

Posted: October 13th, 2014, 9:15 pm
by cameron
Return a struct/class object.

Re: function that returns two values?

Posted: October 13th, 2014, 9:18 pm
by Clodi
thanks mate!
for that simple example you would obviously use a struct right? (not a class)

Re: function that returns two values?

Posted: October 13th, 2014, 9:27 pm
by cameron
Depends, but I would probably do struct.

Re: function that returns two values?

Posted: October 13th, 2014, 9:35 pm
by Clodi
cheers mate

Re: function that returns two values?

Posted: October 14th, 2014, 2:38 am
by Xydrel
Another option, if your compiler has support for C++11, you can set and return a Tuple. That's a multi value object.

Re: function that returns two values?

Posted: October 14th, 2014, 7:24 pm
by albinopapa
Why would anyone use tuple's over structs?