CS202 6- ‹#›
Overloading +, += Operators
nclass string {
n  public:
n    explicit string (char *);  //another constructor
n    friend string operator + (const string &, char *);
n    friend string operator + (char *, const string &);
n    friend string operator + (const string&, const string&);
n    string & operator += (const string &);
n    string & operator += (char *);
n    •••
n};
nstring operator + (const string &s,const string &s2) {
n    char * temp = new char[s.len+s2.len+1];
n    strcpy(temp, s.str);
n    strcat(temp, s2.str);
n    return string(temp);  //makes a temporary object
n}
nstring & string::operator += (const string & s2) {
n    len += s2.len;
n    char * temp = new char[len+s2.len+1];
n    strcpy(temp, str);
n    strcat(temp, s2.str);
n    str = temp;    //copy over the pointer
n    return *this;  //just copying an address
n}
n