Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct A { int a=0, b=0, c=0; };
- struct B: A {
- B() = default;
- B(const B& o):
- A(o), d(o.d?std::make_unique<int>(*o.d):nullptr){}
- B(B&& o) { swap(*this, o); }
- ~B() = default;
- B& operator=(B o) { swap(*this, o); return *this; }
- friend void swap(B&,B&);
- std::unique_ptr<int> d;
- };
- void swap(B& a, B& b) {
- using std::swap;
- swap(static_cast<A&>(a), static_cast<A&>(b));
- swap(a.d, b.d);
- }
Advertisement
Add Comment
Please, Sign In to add comment