#include<iostream> #include<stdlib.h> using namespace std; class MyString { public:     //构造函数     MyString(const char* str = NULL) :m_data(new char[strlen(str)+1])     {         strcpy(m_data,str);     }     //拷贝构造     MyString(const MyString& other)     {         if ((this != &other)&&(&other)!=NULL)         {             strcpy(m_data, other.m_data);         }     }     //析构函数     ~MyString()     {         if (m_data)             delete[] m_data;     }     //赋值函数     MyString& operator=(const MyString& other)     {         if (this != &other)         {             MyString tmp(other);             strcpy(m_data, other.m_data);         }     } private:     char* m_data; };
点赞 评论

相关推荐

牛客小菜鸡66:boss里面,招人的叫老板,找工作的叫牛人
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务