For my custom string class for a class assignment I have the += operator figured out from a previous question but I want to know how to implement the + operator. would I follow similar procedures?
I have already finished the += operator but I want to know how to do the + operator. I have attached the += operator and the signature for the + operator.
DSString operator+(const DSString& src)
{
}
DSString& DSString::operator+=(const DSString& src){
if(src.data != nullptr) {
char *tmp = new char[length + src.length + 1];
strcpy(tmp, data);
strcat(tmp, src.data);
length = length + src.length;
delete [] data;
data = tmp;
}
return *this;
}
I am expecting the string to be able to concatenate together but I have no idea if I can reuse code that I already have or need to start something new.