Shallow Copy And Deep Copy In C++

Video is ready, Click Here to View ×


JOIN ME BEHIND THE SCENE :

In this video we’ill learn shallow copy and deep copy concept. This concept comes when we deal being pointers in class as data members. So when we copy one object to another object hence both objects actually point to the same memory address, to avoid this we use deep copy.
And to achieve deep copy you have to write copy constructor where we will create separate memory for newly created object.

#ShallowCopy #DeepCopy #Cpp #CppTutorial #CppProgramming #CppNuts

c++ compiler

5 Comments on “Shallow Copy And Deep Copy In C++”

  1. Shallow copy -> You just copy the pointer address, basically the your new variable will point to the original object's memory location. Thus, if your new variable is modified, the original object will get modified. eg int b = new int(10); int* a = &b.
    Deep copy -> The original object is copied physically copied and your new variable will hold that copy. If your new variable is modified, the original object will not be modified, as it is physically a different thing. eg int b = 10; int a = b.

  2. Ok. This has to be one of the WORST explanation of deep/shallow copy I've seen in my life. The guy has such a thick accent, its hard to understand what he is saying. The concept is SOOO SIMPLE you can literally explain it in 1 minute to even novice coders.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.