Consider the following example.
#include <string>
template<class CharT, class Traits = std::char_traits<CharT >, class Allocator = std::allocator<CharT >>
void f(const std::basic_string<CharT, Traits, Allocator>& s) {
}
int main() {
f("Hello World!");
}
When compiling it, I get
mismatched types
‘const std::basic_string<_CharT, _Traits, _Alloc>’ and ‘const char []’
Why cannot the compiler deduct "CharT" and do the conversion to the appropriate basic_string<>
? I'd like to have only one signature for f() valid for any argument type for which a conversion to a basic_string<>
exists, is there any solution for this problem?