#include<iostream>
using namespace std;
class String{
public:
String(const char* str=NULL); //赋值构造兼默认构造函数(char):参数可以默认
String(const String &other); //赋值构造函数(String):参数为const类型的引用
String& operator=(const String&other); //operator=:参数为const类型引用,返回引用
String operator+(const String &other)const; //operator+:参数和返回
bool operator==(const String&); //operator==:
char& operator[](unsigned int); //operator[]:
size_t size(){return strlen(m_da
~String(void) {delete[] m_da
private:
char *m_da
};
inline String::String(const char* str)
{
if (!str) m_da
else
{
m_da
strcpy(m_da
}
}
inline String::String(const String& other)
{
if(!other.m_da
else
{
m_da
strcpy(m_da
}
}
inline String& String::operator=(const String& other)
{
if (this!=&other)
{
delete[] m_da
if(!other.m_da
else
{
m_da
strcpy(m_da
}
}
return *this;
}
inline String String::operator+(const String &other)const
{
String newString;
if(!other.m_da
newString = *this;
else if(!m_da
newString = other;
else
{
newString.m_da
strcpy(newString.m_da
strcat(newString.m_da
}
return newString;
}
inline bool String::operator==(const String &s)
{
if ( strlen(s.m_da
return false;
return strcmp(m_da
}
inline char& String::operator[](unsigned int e)
{
if (e>=0&&e<=strlen(m_da
return m_da
}