-
实验目的
掌握 C++语言中重载运算符的方法,体会运算符重载带来的方便。 -
实验内容
(1)完成下列的 String 类,并在主函数 main( )中测试它。
class String
{
public:
String(const char *str = NULL); // constructor
String(const String &other); // copy constructor
~String(void); // destructor
String & operator =(char *str);
String & operator =(const String &other);// 重载=运算符
int operator==(String &other); // 重载==运算符
int operator==(char *str);
void display(); //显示出字符串
private:
char *m_data; // used for storing the string
int length;
};