In certain cases, implicit type conversion may not be desired.
For example:
#include <string>
using namespace std;
void f(bool)
{}
void f(string)
{}
int main()
{
auto p = "hello";
f(p); // Oops!!! Call void f(bool); rather than void f(string);
}
If the C++ standard supports the keyword explicit can be used to qualify function parameters, the code may be changed as follows:
#include <string>
using namespace std;
void f(explicit bool) // Illegal in current C++11 standard!
{}
void f(string)
{}
int main()
{
auto p = "hello";
f(p); // Call void f(string);
bool b = true;
f(b); // Call void f(bool);
f(8); // Error!
}
Why does the C++ standard not support such a handy feature?