How to make a deep copy of this constructor?

c++, copy-constructor

Solution

What is the copy-and-swap idiom?

Deep copies are used so that you can copy all the information that an object has, and then alter the copy without altering the original. Broadly speaking, a shallow copy will copy only the pointer itself, but still point to the same information. This can lead to unexpected changes in data if you're not careful.

Problem

I made this constructor, and I need to make a deep copy of it. I don't really understand the meaning of a deep copy. I know it makes independent copy of an object that has its own dynamic memory, but I don't understand what the need is for this. I'm also not sure how to actually implement the deep copy. Any suggestions? Here is my constructor that I need to make deep copy of: Could anyone provide some syntax help, like a skeleton? ``` template<class t_type> inline ALIST<t_type>::ALIST() { t_type value; capacity=10; DB = new t_type[capacity]; count=capacity; cout<<"Enter value: "; cin.clear(); cin>>value; for(int i=0; i<capacity; i++) { DB[i]=value; } } ```

Original source

Related problems