
Kevin Martin wrote:
I have just discovered to my delight that you can use shared_ptr with a null deleter to pass around stack based objects. This is great because a function shouldn't care whether a parameter passed to it is on the heap or stack. So I can write general functions to accept a shared_ptr and if I have to pass a stack based object I can just pass a null deleter.
I was recently torn between doing this or thinking whether I'm doing it wrong. I'm still not sure whether using shared pointers everywhere with null deleters for stack allocated objects is The Right Thing. It kind of defeats the purpose of shared_ptr which is to ensure that the lifetime of the pointer is guaranteed for you. With null deleters, maintenance programmers may do the wrong thing (stuff something in an event queue deep down, for example.) If anyone has any opinion (for or against) please shout! -- Sohail Somani http://uint32t.blogspot.com