// DEEP COPY
class X
{
private:
int i;
int *pi;
public:
X()
: pi(new int)
{ }
X(const X& copy) // <-- copy ctor
: i(copy.i), pi(new int(*copy.pi)) // <-- note this line in particular!
{ }
};
//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)
{ }
};
Code Example |
---|
Cpp :: initialize string with length c++ |
Cpp :: overload of << c++ |
Cpp :: cout c++ |
Cpp :: what is a template in c++ |
Cpp :: how to read files in c++ |
Cpp :: comparator in sort c++ |
Cpp :: concatenate two vectors c++ |
Cpp :: union of two arrays leetcode |
Cpp :: 3d vector c++ resize |
Cpp :: find kth max and min element in an array |
Cpp :: c++ vector of class objects |
Cpp :: cpp getter as const |
Cpp :: substr in cpp |
Cpp :: c++ add two char together |
Cpp :: power of a number |
Cpp :: insertion sort cpp |
Cpp :: How to get cursor position c++ |
Cpp :: matrix dynamic memory c++ |
Cpp :: print hello world in c++ |
Cpp :: c++ elif |
Cpp :: function overriding in c++ |
Cpp :: structure of a function in C++ |
Cpp :: c++ inheritance |
Cpp :: vector of threads thread pool c++ |
Cpp :: substring in c++ |
Cpp :: find text in string c++ true false |
Cpp :: C++ linked list iterator |
Cpp :: how to declare a 2d vector stack |
Cpp :: sliding window c++ |
Cpp :: c++ prime number |