Trying to passing 2 parameters using 1 function call as the parameters
Hi,
I am trying to call a function that needs two parameters. I know I can do something like this:
add(num(),num());
Where add is a function that needs two parameters and I call the num function twice as those parameters. But can I do something like this:
add(num());
Where add still needs two parameters and the function num returns two like maybe:
1 2 3 4 5
|
int num()
{
int a = 1, b=1;
return a, b;
}
|
Thanks for all the help!
No, you cannot return multiple values from a function. But you you can do this:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
#include <iostream>
typedef int(*num_type)();
int num() { return 1; }
int add(num_type func) {return func() + func();}
int main()
{
std::cout << add(num) << std::endl;
return 0;
}
|
This passes the function num() to add(), which then calls num() twice.
Thanks!
Topic archived. No new replies allowed.