return independant variables in functions
Hi I'm trying to create a function that returns two values independent of each other, like
1 2 3 4
|
float inputInfo (int confNum)
{
return (weight, heightSqd);
}
|
How would I assign each return value to its own variable in main()?
The code you've written is the same as:
1 2 3 4
|
float inputInfo(int confNum)
{
return heightSqd ;
}
|
consult your favorite reference on the comma operator.
You can only return one object/variable from a function.
You can get around that using something like:
1 2 3 4 5 6 7 8 9 10 11 12
|
struct float_2
{
float first ;
float second ;
float_2(float f, float s) : first(f), second(s) {}
};
float_2 inputInfo( int confNum )
{
return float_2(weight, heightSqd) ;
}
|
Last edited on
Topic archived. No new replies allowed.