1// DEEP COPY
2class X
3{
4private:
5 int i;
6 int *pi;
7public:
8 X()
9 : pi(new int)
10 { }
11 X(const X& copy) // <-- copy ctor
12 : i(copy.i), pi(new int(*copy.pi)) // <-- note this line in particular!
13 { }
14};
15
1//SHALLOW COPY
2class X
3{
4private:
5 int i;
6 int *pi;
7public:
8 X()
9 : pi(new int)
10 { }
11 X(const X& copy) // <-- copy ctor
12 : i(copy.i), pi(copy.pi)
13 { }
14};
15