119. Copy Semantics-I

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-assignment

What happens?

Need Help? Refer to the Quick Guide below

Select Answer