Question.4
A developer implements the copy assignment operator for a buffer class:
class Buffer {
uint8_t* data; int size;
public:
Buffer& operator=(const Buffer& other) {
delete[] data;
size = other.size;
data = new uint8_t[size];
memcpy(data, other.data, size);
return *this;
}
};
Buffer buf;
buf = buf; // Self-assignment!
What happens on buf = buf?