【初心者歓迎】C/C++室 Ver.27【環境依存OK】
■ このスレッドは過去ログ倉庫に格納されています
0705デフォルトの名無しさん
2006/05/30(火) 23:52:36class StrType{
char *p;
public:
StrType(){p = NULL;}
StrType(char *Array);
~StrType(){ delete p;}
StrType(const StrType &STobj);
StrType &operator=(StrType &STobj);
StrType &operator+=(StrType &STobj);
char *Get();
friend StrType operator+(StrType &STobj);
};
StrType::StrType(char *Array){・・・}
StrType::StrType(const StrType &STobj){・・・}
StrType &StrType::operator =(StrType &STobj){・・・}
StrType &StrType::operator +=(StrType &STobj){・・・}
char *StrType::Get()
{return this->p;}
StrType operator+(StrType &STobj1, StrType &STobj2)
{
StrType Temp;
Temp.Get() = new char [strlen(STobj1.Get()) + strlen(STobj2.Get()) +1];
strcpy(Temp.Get(), strcat(STobj1.Get(), STobj2.Get()));
return Temp;
}
最後のoperator+の構文がうまくいかないです。
以前ここで、四則演算の演算子のオーバーロードはフレンドが好ましいと聞いたので
フレンドでなんとかやろうとしてるんですが、上手くいかないです。
Temp.Get() = new char [s・・・の式の左のオペラントが正しくないとエラーがでます。
メンバにしてしまえばいけるんですが。
こういう場合はメンバにするしかないんでしょうか。教えてください。
■ このスレッドは過去ログ倉庫に格納されています