实现MyString类--构造函数、拷贝构造函数、析构函数、赋值函数、操作符重载函数
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <assert.h>
using namespace std;
class MyString
{
public:
//MyString(void);
MyString(const char *str=NULL); // 普通构造函数,加NULL包含无参的情况
MyString(const MyString &other); // 拷贝构造函数
~MyString(void); // 析构函数
MyString & operator =(const MyString &other);// 赋值函数
MyString& MyString::operator+(const MyString &other);
MyString& MyString::operator+=(const MyString &other);
void MyString::print_str();
private:
char *m_data;// 用于保存字符串
};
//普通构造函数
MyString::MyString(const char *str)
{
if(str==NULL)
{
m_data = new char[1]; // 得分点:对空字符串自动申请存放结束标志'\0'的//加分点:对m_data加NULL 判断
*m_data = '\0';
}else{
int length = strlen(s