1

I have a function that accepts two integers with default value, is there a way to allow the caller of the functions to pass as many parameters as he wants? (first but not second, second but not first, both). example:

void do_something(int first = 0, int second = 0);

int main()
{
   do_something(1); // first - how to declare it's the first argument
   do_something(1); // second
   do_something(1,1); 
   do_something();
   return 0; // I want to allow all those options
}
Christophe
  • 68,716
  • 7
  • 72
  • 138
CyberGK
  • 47
  • 6

1 Answers1

0

Use another wrapper inline function

   void DoSomething(int f = 0 , int s = 0)
   {}
   void inline DoSomethingS(int s = 0)
   {DoSomething(0 , s);}

If the user wants to send the second and leave the first optional he'll use the DoSomething+options in this case DoSomethingS.

Paul Sanders
  • 24,133
  • 4
  • 26
  • 48
tomer zeitune
  • 1,080
  • 1
  • 12
  • 14