Is it possible to use previous arguments in a functions parameter list as the default value for later arguments in the parameter list? For instance,
void f( int a, int b = a, int c = b );
If this is possible, are there any rules of use?
Rule Details. This rule enforces default parameters to be the last of parameters.
Constructors cannot have default parameters.
A default argument is a value provided in a function declaration that is automatically assigned by the compiler if the calling function doesn't provide a value for the argument. In case any value is passed, the default value is overridden.
The answer is no, you can't. You could get the behaviour you want using overloads:
void f(int a, int b, int c); inline void f(int a, int b) { f(a,b,b); } inline void f(int a) { f(a,a,a); }
As for the last question, C doesn't allow default parameters at all.
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