Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Function overloading does not actually "fail" in the presence of default parameters. However, when a function is overloaded and some of the overloaded versions have default parameters, it can lead to ambiguity in some situations.

For example, consider the following two functions:

void foo(int a, int b = 0);
void foo(int a, int b);

When the compiler encounters a call to foo with two integer arguments, it will be ambiguous which of these functions to call. This is because both functions could be called with two arguments, and the first function could also be called with just one argument (since b has a default value).

To avoid this ambiguity, one of the functions could be renamed, or the default parameter could be removed.