Answers for "Why do you need to implement a copy constructor and assignment operator? In this answer also describe difference between shallow copy vs deep copy."

C++
4

deep copy c++

//SHALLOW COPY
class X
{
private:
    int i;
    int *pi;
public:
    X()
        : pi(new int)
    { }
    X(const X& copy)   // <-- copy ctor
        : i(copy.i), pi(copy.pi)
    { }
};
Posted by: Guest on November-01-2020

Code answers related to "Why do you need to implement a copy constructor and assignment operator? In this answer also describe difference between shallow copy vs deep copy."

Browse Popular Code Answers by Language