Shallow Copy and Deep Copy in C++

352 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

Think of memory like URLs and websites.

If you want to access some memory, the computer checks the URL, the URL brings you to a website, and the website contains the data the computer wants.

Shallow copy would be like copying the URLs. If you access the URL, you’ll get whatever data the URL brings you to. The website may or may not have changed.

Deep copy would be like going to the URL and copying the HTML of the website, and then saving that under a different URL. This way, even if the website at the original URL changes, the one you deep copied will remain the same as when you originally copied it.

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