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