#include<stdio.h>
#include<string.h>
class String{
public:
String(const char *str = NULL);
char *m_data;
char *addstr;
String &operator + (const String *rhs);
};
String :: String(const char *str){ //定义构造函数
if(str == NULL){
m_data = new char[1];
m_data[0] = ‘\0‘;
}else{
m_data = new char[strlen(str)+1];
strcpy(m_data,str);
}
}
String &String :: operator+(const String &rhs){ //重载加法运算
addstr = new char[strlen(m_data)+strlen(rhs.m_data)+1;
strcpy(addstr,m_data);
}
时间: 2024-11-27 23:13:22