Search code examples
c++boostshared-ptr

boost::shared_ptr destroy callback


I was digging through documentation of boost, looking for callback which is called just before object in boost::shared_ptr is being deleted, so i can write object state back to hard drive, and remove weak_ptr element from std::map.

Does anyone know how to deal with this problem?


Solution

  • You can pass a deleter function to shared ptr and write object state in this function.

    template<class Y, class D> shared_ptr(Y * p, D d);