C++:隐式转换顺序

c++: implicit conversion order

我有一个像这样重载的(成员)函数:

bool foo(bool);
int foo(int);
float foo(float);
...
std::string foo( std::string const&);

一些内置类型,但不适合 const char*。调用 foo("beauty is only skin-deep");,令我大吃一惊,调用了 foo 函数的布尔变量。这引出了我的问题:

问题:是否有明确定义的内置类型隐式转换顺序

不是问题:如何避免隐式转换。隐式转换是多么邪恶。 ...

编辑: 删除了关于用户定义问题的隐式转换顺序的问题

根据:http://en.cppreference.com/w/cpp/language/implicit_cast

所有内置转换都发生在用户定义的转换之前

pointer -> bool 是 'Boolean conversions'(if(pointer) 表示法需要),'numeric conversions'

的最后一个

'const char*' -> std::string 从语言的角度来看是 'user defined conversion',std::string 是用户定义的类型。

不幸的是,最简单的解决方案是编写适当的 fun(const char*) 重载,或者避免 fun(bool) 与 fun(std::string) 重载