<分区>
我有两个重载函数,分别是 const std::string& 和 bool。我现在用文字字符串调用函数。 bool 版本被调用。这有点奇怪,而且确实是一个陷阱。
谁能解释一下为什么?
请参阅下面的代码。输出是
Write == 1
#include <iostream>
#include <string>
void write(const std::string& name_) {
std::cout << "Write == " << name_ << std::endl;
}
void write(bool name_) {
std::cout << "Write == " << name_ << std::endl;
}
int main()
{
write("data");
}