I know it's possible to do something like :
int foo(int a = 0, int b = 1) { return a + b; }
and then use it without the default parameters eg.:
foo(); // a = 0, b = 1 -> 1
or with the last one as default eg.:
foo(2); // a = 2 and b = 1 default -> 3
But my question is: Is it possible to use the default value for the first argument (a) and give the value of the second (b)
My first thought was doing it like (which doesn't work!):
foo(,2); // a = 0 default and b = 2
Does a syntax for this exist or is this just not possible ?
No, it is not possible in current syntax.
Alternatively from specifying default parameter values you can use multiple function overloads like:
int foo(int a, int b){return a+b; }
int foo(int b){return foo(0,b); }
int foo(){return foo(0,1); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With