This Buffer has no copy constructor of its own – submit it as-is and look closely at the output. a.data[0]
comes out 999, even though nothing ever wrote to a directly, and (if you run it enough times, or check the
exit behavior) it eventually crashes with a double-free – exactly the lesson’s worked example, unmodified.
The fix is exactly what the previous exercises built: add a deep-copy copy constructor to Buffer, so Buffer b = a; gives b its own independent array instead of a second reference to a’s. Nothing else in this file needs to
change – main never assigns to an existing Buffer here (there’s no b = a; with b already constructed),
only the copy constructor is actually exercised.