Implementing Assignment Operator

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;
}

Implementing Destructor

~mystring(){
	if (buf != nullPtr){
		delete []buf;
		buf = nullPtr;
	}
}

Summary for Constructors and Operators

Copy Constructors

mystring b(a);
mystring b = a;
mystring *p = new mystring(a);

Assignment Operators

mystring b, a;
b = a; // this calls the copy cnstrtr
b.operator=(a); // line 2 is this

Can we implement operator== for the mystring class?