← Copy Semantics: The Copy Constructor & Copy Assignment Operator

Copy Assignment Between Objects

medium

a and b are two already-existing Buffers of possibly different sizes – b = a; needs to make b an independent deep copy of a, resizing b’s array to match a’s in the process. This is genuinely different work from the copy constructor: b already owns memory from its own constructor, and that memory has to be released before b can take on a’s size and contents, or the original allocation simply leaks.

This exercise doesn’t require a self-assignment guard (a and b are always distinct objects here) – the next exercise covers exactly that case on its own.

Your solution

"Run" uses the sample stdin ("3 5"). "Submit" checks your code against all 3 test cases.

Test results

Submit your solution to run it against all test cases.

Hints

    Reference solution