Q:

Type conversion for std::strings

Is it possible to have something like a global type conversion operator functions for a class? I am specifically looking for a way to expose the const char* from the std::string. I tried defining a global operator but that doesn't compile. With a quick search and looking at the cpp reference these user defined conversion needs to be member http://en.cppreference.com/w/cpp/language/cast_operator.
Is there any kind of clean (or hacks) way of passing the std::string to methods that accepts const char* without always using the c_str().
Background:
I am working on a cross platform and I am primarily from windows. Most of my classes uses the ATL::CString. And I am changing them to use std::string's. Invoking c_str is fine, but in the unit test code there seem to be too much of this call every line and every args, so trying to be lazy here.

A:

Just as only user-defined types can define their own constructors, only user-defined types can define whether they are implicitly convertible to other types (or from other types via non-explicit constructors). So no, you cannot force an implicit conversion from std::string to const char* from outside the class.

