tags:

views:

13

answers:

1

For example if I have an object that contains a pointer to a dynamically allocated object, then assign it to another object with the same type, i.e.

object2 = object1;

and the destructor will explicitly delete the dynamically allocated object. So when object2 and object1 go out of scope, an error will occur (which I assume to be because the address for the dynamically allocated object is deleted twice). So what should I do to fix/avoid this problem?

A: 

I'm guessing this is C++? In which case, take a look at smart pointers. Reference counting (boost::shared_ptr) helps take care of this sort of problem.

Jeff Foster

related questions