class mystring {
private:
string s;
public:
mystring(string ss) {
cout << "mystring : mystring() : " + s <<endl;
s = ss;
}
/*! mystring& operator=(const string ss) {
cout << "mystring : mystring& operator=(string) : " + s <<endl;
s = ss;
//! return this;
return (mystring&)this; // why COMPILE ERROR
} */
mystring operator=(const string ss) {
cout << "mystring : mystring operator=(string) : " + s <<endl;
s = ss;
return *this;
}
mystring operator=(const char ss[]) {
cout << "mystring : mystring operator=(char[]) : " << ss <<endl;
s = ss;
return *this;
}
};
mystring str1 = "abc"; // why COMPILE ERROR
mystring *str2 = new mystring("bcd");
だから質問は
正しいmystring&opeartor =オーバーロードを作成する方法、つまり、ポインターではなく参照を返すにはどうすればよいですか(C ++で参照とポインターの間を転送できますか?)
正しいmystringoperator=overloadを作成する方法?ソースコードは正常に機能すると思いましたが、operator =をオーバーロードしなかったかのように、mystringにconstchar[]を割り当てることができませんでした。
ありがとう。