Can a C++ default argument be initialized with another argument? [duplicate]

Another argument cannot be used as the default value. The standard states:

8.3.6 Default arguments

9 A default argument is evaluated each time the function is called with no argument for the corresponding
parameter. The order of evaluation of function arguments is unspecified. Consequently, parameters of a
function shall not be used in a default argument, even if they are not evaluated.

and illustrates it with the following sample:

int f(int a, int b = a); // error: parameter a
                         // used as default argument

Leave a Comment