Define a conversion operator:
class SomeClass { public: operator std::string () const { return "SomeClassStringRepresentation"; } };
Note that this will work not only in function calls, but in any context, the compiler will try to match the type with std::string - with initialization and assignments, operators, etc. Therefore, be careful with this, as it is all too easy to make the code difficult to read with many implicit conversions.
source share