For example, something like this:
#include <cstdarg>
void my_function(int it=42, ...)
{
/* va_list/start/arg/end code here */
}
What exactly does the above code mean in C++? It compiles fine in G++. Note, I can’t imagine any scenario where this would be useful or even what it ought to do. I’m just curious.
You said this function compiles fine with GCC, but you cannot make use of the default argument, you will have to pass argument for the so-called default parameter as well, to work with this function.
Ask yourself:
Is the first argument
898corresponds to the parameteritor it corresponds to the variadic parameter (and you intend to use the default value42forit)?The compiler cannot know your intention!
BTW @Johannes pointed out a good point : you can simply call
my_function()without passing any argument. That is the only instance I see when you can make use of the default argument.Now if you change the position of the default parameter, something like this:
Then this is illegal in C++ to begin with.
Again, ask yourself : if it was allowed then you could call this as:
Is the last argument
7897corresponds to the parameterpor it corresponds to the variadic parameter (and you intend to use the default value10forp)?The compiler cannot know your intention in this case either.