Normally, EscapedString es2 = es;
will call the copy constructor, however you explicitly told it not to by making the copy constructor explicit
:
explicit EscapedString(const EscapedString &strEscaped)
A constructor marked explicit
can never be called by means of automatic type conversions. It can only be called, well... explicitly, which you have done here:
EscapedString es(EscapedString("Abc?def"));
Here's what happens when the compiler encounters EscapedString es2 = es;
.
First the compiler sees if it can use the copy constructor and finds that it can't, because it was marked explicit
. So it looks for another constructor to call. Since EscapedString
is derived from std::string
, the compiler is able to cast es
as a const std::string&
and call:
EscapedString &operator=(const std::string &strUnEscaped)