Optional argument value

I want to create a function with an optional argument that takes the value of another argument. In the function declaration, the following does not work, but this is exactly what I want to do:

void function(int a, int b=a)   //error

I am trying to set the default value of variable b to value a. What is the cleanest way to do this? Can we do this without changing the signature of the function?

+4
source share
2 answers

Write an additional function that takes only one argument and calls the original function:

inline void function(int a)
{
    function(a, a);
}
+10
source

The default argument should be global variableor global constant, even function. But this cannot be local variable, because it local varcannot provide in the assembly.

+1

All Articles