#include <iostream> #include <string.h> using namespace std; class String { public: String(const char * x=NULL); String(const String & x); ~String(); String & operator= (const String & x); String & operator= (const char * x); bool operator== (const String & x); bool operator!= (const String & x); bool operator< (const String & x); bool operator> (const String & x); String & operator+= (const String & x); String & operator+= (const char *x); char & operator[] (int i); char & operator() (const char * x); const char * str(void); unsigned int length(void); //friend函数可以任意定义到public, protect, or private //friend函数可以任意访问public, protected or private的数据 friend ostream & operator<<(ostream & out, String & x); friend void test (String & x); friend void test (void); private: char * m_string; unsigned int m_size; static int t; //test()测试用 }; int String::t = 0; String::String(const char * x) { if (x == NULL) { m_string = new char[1]; m_string[0] = '