The compiler cannot do this far; you will either have to explicitly call the translation operator, or explicitly specify the template parameter:
G(static_cast<std::string>(a)); G<char>(a);
To understand why the compiler cannot perform both the user-defined conversion and the argument of the template argument, take this example:
template<typename T> struct Number { Number(double n) {}; Number(int n) {}; }; struct A{ operator Number<double>(){return Number<double>(1.);} operator Number<int>(){return Number<int>(1);} }; template<typename T> void G(Number<T>& number) { } int main(){ A a; G(a);
What should the compiler do in this case?
source share