Skip to main content

Practice · 2 of 2

Rule of Three: a deep-copying Blob

CHALLENGE
Difficulty: intermediate+25 XP

Implement class Blob owning int* data_; std::size_t n_;: constructor Blob(std::size_t n) zero-initializes heap memory, destructor frees it, copy constructor deep-copies, and copy assignment deep-copies with a self-assignment guard. Provide std::size_t size() const and int& at(std::size_t). The test mutates a copy and checks the original is untouched (deep, not shallow).

Back to lesson: Practice: Rule of Three and move semantics