I have two overload function with const std::string& and bool respectively. I am now calling the function with literal string. The bool version is called. This is a bit weird, and it is really a pitfall.
Can anyone explain why?
See the code below. The output is
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");
}