1.已知类MyString的原型为:
class MyString{
public: MyString(const char *str=NULL);//普通构造函数
MyString(const MyString);//拷贝构造函数
~MyString(void);//析构函数
MyString&operator=(const MyString);//赋值构造函数
private:char *m_c_data;//用于保存字符串
};请编写MyString的上述4个函数。
程序猿面试宝典p112
class MyString
{
public:
MyString(const char *str=NULL);//普通构造函数
MyString(const MyString &other);//拷贝构造函数
~MyString(void);//析构函数
MyString&operator=(const MyString &other);//赋值构造函数
private:
char *m_data;//用于保存字符串
};
MyString::MyString(const char *str)//构造函数
{
if(str==NULL)
{
m_data=new char[1];
*m_data='