Default argument value vs. overload

Note that overloads should be chosen with care, because it’s easy to create overloads that break existing code. For example:

void DoSomething(double a, bool useNewMode);
void DoSomething(double a, double multiplier);

void myfunction()
{
  // this used to work, until someone overloaded the function
  DoSomething(10, 1);
}

Example compile error:

ambiguous.cxx:7:14: error: call of overloaded ‘DoSomething(int, int)’ is ambiguous
   17 |   DoSomething(10, 1);
      |   ~~~~~~~~~~~^~~~~~~
ambiguous.cxx:1:6: note: candidate: ‘void DoSomething(double, bool)’
    3 | void DoSomething(double a, bool useNewMode)
      |      ^~~~~~~~~~~
ambiguous.cxx:2:6: note: candidate: ‘void DoSomething(double, double)’
    8 | void DoSomething(double a, double multiplier)
      |      ^~~~~~~~~~~
2 Likes