I reviewed my notes and added operator +
DString& DString :: operator = (const Dstring& s){
delete[ ] this ->data;
this -> data = (char*)0;
this -> size = s.size;
this -> data = new char[this->data+1];
strcpy(this->data, s.data);
teturn *this;
}
DString& DString :: operator += (const DString& s){
char* temp = new char[this->size+s.size+1];
strcpy(temp, this->data);
strcat(temp, s.data);
this->size += s.size;
delete [ ] this -> data;
this ->data = temp;
return * this;
}
DString& DString :: operator + (const DString& s){
char* temp = new char[this->size+s.size+1];
strcpy(temp, this->data);
strcat(temp, s.data);
DString ds(temp);
delete[ ] temp;
return ds;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment