Your statement is templated, so template arguments must be inferred. You cannot do this because the compiler is trying to map basic_string<_CharT, _Traits, _Alloc> to your Location , and it does not work.
So the problem is overloading, not conversion, because the code actually never reaches that point.
Change this:
std::string s2 = "Line: "s + loc + "\n"s;
:
std::string s2 = "Line: "s + std::string(loc) + "\n"s;
and everything should be fine, because if you look closely at the compiler error, it mentions:
template argument deduction/substitution failed: prog.cc:22:32: note: 'Location' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>' std::string s2 = "Line: "s + loc + "\n"s; // error ^~~
and other similar messages.
source share