According to my compiler gcc-4.6 the call to func in the example below is ambigous.
void func(const std::string &str) {
}
void func(std::function<std::string()> f) {
}
void test() {
func("Hello");
}
Is the compiler correct in saying this? If I remove the first overload this code won’t compile as it will fail to instantiate the templates involved.
Is there anyway to resolve this beside either renaming one of the two functions or by explicitly converting to std::string?
You could also add a third overload to explicitly capture the string literal case: