【发布时间】:2017-10-16 17:55:52
【问题描述】:
我有以下代码:
#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;
}
执行时我得到这个输出:
bool
我会期望输出:
string
为什么 g++ 4.9 会隐式将此字符串强制转换为 bool?
【问题讨论】: