← The Rule of Three (and Five) & RAII

Fix: Missing Copy Assignment

hard

This Buffer looks well-written – a correct destructor, a correct copy constructor – and it’s still buggy. Run it as-is: b = a; uses the compiler-generated default copy assignment operator, since none was written, and that default is the same shallow copy from two lessons ago. a.data[0] ends up 999 even though only b.data[0] was ever assigned to.

This is the Rule of Three’s real failure mode in practice: it’s rarely “forgot all three at once.” It’s usually “wrote two of the three correctly, and the class still isn’t safe” – because all three are required together, not individually. Add the missing operator=.

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