void moveToPool(MyObject* obj) { ... }typedef shared_ptr<MyObject> MyObjectPointer;...MyObjectPointer pObject(new MyObject(...), moveToPool);
In the above example the function moveToPool will be called when the last instance of the shared pointer expires. Note that you can copy the shared_ptr as often as you want, all instances will keep track of the deleter function.
This is also very useful if you want to manage an entity which has to be cleaned up by a library function instead of delete (for example cvReleaseImage in OpenCV).