文字列クラスの深いコピー(2種類)と浅いコピー(3種類)
747 ワード
#include
using namespace std;
// :
//class String
//{
//public:
// //
// String(char *string="")
// :_str(new char[strlen(string)+1])
// {
// strcpy(_str, string);
// }
// // , ,
// // , , , ,
// String(const String& s)
// :_str(new char[strlen(s._str)+1])
// {
// strcpy(_str, s._str);
// }
//
// String& operator = (const String& s)
// {
// if(this!=&s)
// {
// delete[] _str;// , , “”
// _str = new char[strlen(s._str) + 1];
// strcpy(_str, s._str);
// }
// return *this;
// }
// ~String()
// {
// delete[] _str;
// }
// void Display()
// {
// cout <