C++ conversion operator between types in other libraries
- by Dave
For convenience, I'd like to be able to cast between two types defined in other libraries. (Specifically, QString from the Qt library and UnicodeString from the ICU library.) Right now, I have created utility functions in a project namespace:
namespace MyProject {
const icu_44::UnicodeString ToUnicodeString(const QString& value);
const QString ToQString(const icu_44::UnicodeString& value);
}
That's all well and good, but I'm wondering if there's a more elegant way. Ideally, I'd like to be able to convert between them using a cast operator. I do, however, want to retain the explicit nature of the conversion. An implicit conversion should not be possible.
Is there a more elegant way to achieve this without modifying the source code of the libraries? Some operator overload syntax, perhaps?