i want to create a function with an optional argument which take the value of another argument. In the declaration of the function the following doesn't work, but this is exactly what i want to do :
void function(int a, int b=a) //error
I try to set the default value of the variable b to the value of a. What is the cleanest way to do that ? Can we do that without changing the signature of the function ?
Write an additional function that takes just one argument and calls the original function:
inline void function(int a)
{
function(a, a);
}
Default argument must be global variable
or global constant
, even function
. But it can not be local variable
, because local var
can not ensure in build.
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