If I create a function with default value inputs like this prototype:
void F(int a = 0, int b = 1, int c = 2);
And I want to call this function with default value only for second variable something like this:
F(2, , 3);
means i want to pass 2 for the first, 3 for the third variable but i want the second one to get the default value.
How can i do this?
#include <iostream>
int F(int a = 0, int b = 1, int c = 2)
{
if (a == -1) a = 0;
if (b == -1) b = 1;
if (c == -1) c = 2;
return a * b * c + a + b + c;
}
int main()
{
std::cout << F() << std::endl; // F( , , )
std::cout << F(1,2) << std::endl; // F(1,2, )
std::cout << F(1, -1, 3) << std::endl; // F(1, ,3)
std::cout << F(-1, 2, 3) << std::endl; // F( ,2,3)
return 0;
}
If you want it to be trickier, you can do something like this: