C.22 Fixes a mistake in the code example not making a deep copy (#1573)

This commit is contained in:
Adnn
2020-02-27 20:18:08 +01:00
committed by GitHub
parent fc383d6641
commit 2f0c2e5874

View File

@@ -4701,7 +4701,7 @@ Users will be surprised if copy/move construction and copy/move assignment do lo
}; };
shared_ptr<Impl> p; shared_ptr<Impl> p;
public: public:
Silly(const Silly& a) : p{a.p} { *p = *a.p; } // deep copy Silly(const Silly& a) : p(make_shared<Impl>()) { *p = *a.p; } // deep copy
Silly& operator=(const Silly& a) { p = a.p; } // shallow copy Silly& operator=(const Silly& a) { p = a.p; } // shallow copy
// ... // ...
}; };