nAlternative implementations, not as
efficient:
n
nstring operator + (const
string &s, char *lit) {
n string
temp;
n temp.len
= s.len+strlen(lit);
n temp.str = new char[temp.len+1];
n strcpy(temp.str, s.str);
n strcat(temp.str, lit);
n return temp;
n}
n
nDon’t do the
following....
nstring &
string::operator += (const string & s2) {
n
n return *this=*this+s2; //Extra unnecessary deep copies
n}
n