我有以下代码:
#include <iostream>
#include <string>
void foo(bool a)
{
std::cout << "bool" << std::endl;
}
void foo(long long int a)
{
std::cout << "long long int" << std::endl;
}
void foo(const std::string& a)
{
std::cout << "string" << std::endl;
}
int main(int argc, char* args[])
{
foo("1");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
执行时我得到这个输出:
bool
Run Code Online (Sandbox Code Playgroud)
我原以为输出:
string
Run Code Online (Sandbox Code Playgroud)
为什么g ++ 4.9隐式将此字符串转换为bool?