boost::shared_ptr and custom handling of delete
Hello, The type of shared pointer I have in mind is boost::shared_ptr. Is there some way I can extend/modify (short of re-writing) cleanly its functionality such that when its reference counter becomes zero, a method in the actual pointer's class is called instead of that class's destructor being called? Consider the following snippet to allow me to explain: class A { public: A() { } ~A() { } void deleteA() { } }; boost::shared_ptr<A> a(new A); a.reset(); In this example, when a.reset() is called A's I want the deleteA() method to be called instead of the destructor for A. It would then be up to deleteA() to decide if/when to cause the delete of the real object. Best regards, -Arun.
Arun Dharankar wrote:
The type of shared pointer I have in mind is boost::shared_ptr. Is there some way I can extend/modify (short of re-writing) cleanly its functionality such that when its reference counter becomes zero, a method in the actual pointer's class is called instead of that class's destructor being called?
Consider the following snippet to allow me to explain:
class A { public: A() { } ~A() { } void deleteA() { } };
boost::shared_ptr<A> a(new A); a.reset();
In this example, when a.reset() is called A's I want the deleteA() method to be called instead of the destructor for A. It would then be up to deleteA() to decide if/when to cause the delete of the real object.
boost::shared_ptr supports this through a second argument to its constructor. boost::shared_ptr<A> a(new A, boost::bind(&A::deleteA, _1)); KevinH -- Kevin Heifner heifner @ ociweb.com http://heifner.blogspot.com Object Computing, Inc. (OCI) www.ociweb.com
participants (2)
-
Arun Dharankar
-
Kevin Heifner