class MyString{ public:     MyString(const char *str);     MyString(const MyString &other);     ~MyString(void);     void put_my(void);     MyString & operator = (const MyString & other); private:     char *m_data; }; MyString::MyString(const char *str) {     m_data =new char[strlen(str)+1];     strcpy(m_data,str); } MyString::MyString(const MyString &other) {     m_data =new char[strlen(other.m_data)+1];     strcpy(m_data,other.m_data); } MyString::~MyString(void) {     delete[] m_data; } MyString& MyString::operator= (const MyString & other) {     if(&other!=this)     {         MyString str(other);         delete[] m_data;         m_data =new char[strlen(other.m_data)];         strcpy(m_data,other.m_data);     }     return *this; } void MyString:: put_my(void) {     cout<<m_data<<endl; }
点赞 评论

相关推荐

牛客网
牛客网在线编程
牛客网题解
牛客企业服务