String类型
#include <iostream>
using namespace std;
class String
{
public:
String(const char *str = nullptr)//普通构造函数
{
if (str != nullptr)
{
m_data = new char[strlen(str) + 1];
strcpy(m_data, str);
}
else
m_data = new char[1];
*m_data = '\0';
}
String(const String &other)//拷贝构造函数
{
m_data = new char[strlen(other.m_data)+1];
strcpy(m_data, other.m_data);
}
~String(void)//构造函数
{
delete[]m_data;
m_data = nullptr;
}
//string&是为了支持连续的operator=赋值操作
String& operator=(const String &other)//赋值函数
{
if (this == &other