期待どおりに動作するコードがあります:
EscapedString es("Abc&def");
EscapedString es2("");
es2 = es; // es2 == Abc%26def
期待どおりに動作しないコード:
EscapedString es("Abc&def");
EscapedString es2 = es; // es == Abc%2526def
2 番目のケースでは、EscapedString であっても CTOR3 の代わりに CTOR2 が呼び出されes
ます。
EscapedString es(EscapedString("Abc?def"));
正しいことを行いますが、CTOR3 にブレークポイントを設定できないように見えるため、正しく動作しているか、コードが最適化されているか、誤って動作しているかはわかりません。
クラスは以下です。
class EscapedString : public std::string {
public:
EscapedString(const char *szUnEscaped) { // CTOR1
*this = szUnEscaped;
}
EscapedString(const std::string &strUnEscaped) { // CTOR2
*this = strUnEscaped;
}
explicit EscapedString(const EscapedString &strEscaped) { // CTOR3
*this = strEscaped; // Can't set breakpoint here
}
EscapedString &operator=(const std::string &strUnEscaped) {
char *szEscaped = curl_easy_escape(NULL, strUnEscaped.c_str(), strUnEscaped.length());
this->assign(szEscaped);
curl_free(szEscaped);
return *this;
}
EscapedString &operator=(const char *szUnEscaped) {
char *szEscaped = curl_easy_escape(NULL, szUnEscaped, strlen(szUnEscaped));
this->assign(szEscaped);
curl_free(szEscaped);
return *this;
}
EscapedString &operator=(const EscapedString &strEscaped) {
// Don't re-escape the escaped value
this->assign(static_cast<const std::string &>(strEscaped));
return *this;
}
};