I also went through this problem recently, let me share another way.
You can change the bool constructor to an unsigned char . Thus, the decomposition and implication of the conversion of the string literal does not occur, and the constructor std::string takes place.
class A { public: A(string v) { cout << v; } A(unsigned char v) { cout << static_cast<bool>(v); } }; int main() { A("Hello");
Thus, you do not need to always overload to std::string and const char* without creating a bloat code, creating std::string on the client call site.
I do not claim to be better, but it is easier.
Nico engels
source share