Overload resolution has several steps: First, a set of viable functions is selected. These viable functions must have enough parameters for the call, considering ellipsis and/or default arguments. In addition, each argument has to be convertible to the corresponding parameter type. For c.send_command("GET", "foo");
you have as viable candidates
virtual void send_command( const std::string&, const std::string&, bool);
virtual void send_command( const std::string&, bool);
because the third parameter of the former is defaulted and the string literal arguments are convertible to string const&
and bool
.
After having the viable set, the compiler looks at the argument conversions needed. No conversion is prefered, then builtin conversions, then user defined conversions. In this case, the conversion for the first argument is the same in both viable functions. For the second argument, the conversion to bool
is buitlin, while the conversion to string const&
is not. Therefore send_command( const std::string&, bool);
is prefered over the alternative.