Question.4
A developer writes a copy assignment operator without a self-assignment check:
Buffer& operator=(const Buffer& o) {
delete[] ptr; // Free old
size = o.size;
ptr = new int[size]; // Allocate new
memcpy(ptr, o.ptr, size * sizeof(int));
return *this;
}
Buffer buf(10);
buf = buf; // Self-assignmentWhat happens?