In this case, since we are assigning some string other to our existing one, there is a buffer that exists and needs to be deleted.
mystring& mystring::operator=(const mystring& other){
if (this == &other) // we have to implement operator ==
return *this;
delete []buf;
buf = new char[other.len + 1];
strcpy(buf, other.buf);
len = other.len;
return *this;
}
~mystring(){
if (buf != nullPtr){
delete []buf;
buf = nullPtr;
}
}
mystring b(a);
mystring b = a;
mystring *p = new mystring(a);
const for safetymystring b, a;
b = a; // this calls the copy cnstrtr
b.operator=(a); // line 2 is this
const for safetyCan we implement operator== for the mystring class?