ExceptionsWhen used sparingly and with care, implicit conversions can make calling code short and intuitive. The standard std::string defines an implicit constructor that takes a const char*. This works fine because the designers took some precautions:
Even so, there can still be some weirdness with overloaded functions:
void Display( int );
void Display( std::string );
Display( NULL ); // calls Display(int)
This result might be surprising. (Incidentally, if it did call Display( std::string ), the code would have exhibited undefined behavior because it's illegal to construct a std::string from a null pointer, but its constructor isn't required to check for the null.) |