Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Foo {
- public:
- Foo(A* a, B* b) : a(a), b(b) {}
- ~Foo() {
- delete a;
- delete b;
- }
- Foo(const Foo& rhs) {
- operator=(rhs);
- }
- Foo& operator=(const Foo& rhs) {
- if (this == &rhs)
- return *this;
- if (a) {
- delete a;
- a = 0;
- }
- if (b) {
- delete b;
- b = 0;
- }
- try {
- if (rhs.a)
- a = new A(*rhs.a);
- if (rhs.b)
- b = new B(*rhs.b);
- } catch (...) {
- if (a)
- delete a;
- throw;
- }
- return *this;
- }
- private:
- A* a;
- B* b;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement