I'm refactoring parts of an existing application to use shared_ptrs instead of raw pointers. What is the best way to deal with code like this (please note in this situation passing a pointer to a stack-allocated object to function is acceptable and safe): void function (shared_ptr<Object> ptr) { ... } void function2 () { Object o; function(&o); // <--- need to change this } It seems I have two choices, I am not sure which is better, or if there are other common techniques. I can either use a no-op delete function: void noop (Object *) {} void function2 () { Object o; function(shared_ptr<Object>(&o, noop)); } Or I can allocate it on the heap instead of the stack, and let shared_ptr deal with the cleanup (this seems to be the more convenient solution): void function2 () { shared_ptr<Object> o(new Object); function(o); } What's the normal practice here? Thanks, Jason