I have a class which has a conversion operator for type std::string marked as explicit. Here is the class
class MyClass {
public:
// methods ...
explicit operator std::string() const {
// convert to string ...
}
}
Problem is when I use static_cast on a variable of type MyClass I get the error "No matching conversion for static_cast from 'MyClass' to 'std::string aka …" I seem to have the same problem when I define conversion operators for any custom type. Is the explicit modifier only defined for conversion to primitive types or is this another compiler bug.
using namespace std
? The shame. – Yakk - Adam Nevraumont