In C ++ 03 or C ++ 11 without specifying the semantics of movement, the implicit conversion const char * to std::string creates a temporary string, which is then copied to the member. This implements an extra copy.
In C ++ 11, instead of an intermediate value, you can move the temporary code:
construct( std::string s ) : member( std::move( s ) ) {}
The only thing I can think of is compatibility with other classes that provide conversion operators.
struct String { operator char const * () const; };
Since only one user-defined conversion can be applied implicitly, the std::string function will not receive a String argument by converting via char const * . Note, however, that with the extra conversion function to std::string and both constructors, the result will be an overload error.
Potatoswatter
source share