1) won't work because you're trying to use a const char[10] instead of a std::string
2) should work and so should 3) since default template parameters should ensure you're using defaults
#include <iostream>
using namespace std;
template <class CharType>
void Foo(const std::basic_string<CharType> &s)
{
cout << s.c_str(); // TODO: Handle cout for wstring!!!
}
void Foo(const char *s)
{
Foo((std::string)s);
}
int main()
{
std::wstring mystr(L"hello");
Foo(mystr);
Foo("world");
Foo(std::string("Im"));
Foo(std::basic_string<char>("so happy"));
return 0;
}
Careful when dealing with template parameters. I also provided a small overload for wstring, see if that fits you.