c ++:隐式转换顺序

use*_*183 4 c++ language-lawyer implicit-conversion

我有一个(成员)功能重载像这样:

bool foo(bool);
int foo(int);
float foo(float);
...
std::string foo( std::string const&);
Run Code Online (Sandbox Code Playgroud)

对于几种内置类型但不适用于const char*.打电话foo("beauty is only skin-deep");,我的大惊喜,叫foo的函数的布尔变.这引出了我的问题:

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

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

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

Hco*_*org 7

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

所有内置转换都在用户定义的转换之前进行

指针 - > bool是'布尔转换'(if(指针)表示法需要),最后是'数字转换'

'const char*' - > std :: string是一个'用户定义的转换',从语言的角度来看,std :: string是用户定义的类型.

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