Shallow Copy and Deep Copy in C++

350 views

What are the differences between the two and when should you worry about creating a deep copy?

In: 1

4 Answers

Anonymous 0 Comments

Let’s say you have a bookshelf, and a list of all the titles/locations of the books on the shelf.

When you create a shallow copy, you’re copying the list of titles/locations of the books.

When you create a deep copy, you’re copying the list but ALSO the bookshelf and the books on it.

The former is quick and doesn’t require much space at all to make the copy. The latter is much more labor-intensive and needs lots more space for everything.

Really depends on how important certain factors are like speed/time/memory available…

You are viewing 1 out of 4 answers, click here to view all answers.