It smells of bad design.
I cannot think of a reasonable situation when you do not want to delete the pointer. Here are the situations (unreasonable IMO):
1) static objects of duration. Instead, consider using a singleton mixin (use CRTP to mix a singleton that has an instance () method that returns a copy of the local static shared_ptr <>; local statics are unsafe, so you'll also need an appropriate static mutex if it can be called by multiple threads) . The advantage of using the correct singleton is that your singleton will be destroyed when exiting after other objects that continue to hold shared_ptr <> for it.
2) objects created on the stack. Just don't do it. Instead, create an object on the heap protected by shared_ptr <>. If you need to create shared_ptr <> for an object in different parts of the code (i.e. you cannot take copies from the original shared_ptr <>), then inherit from boost :: enable_shared_from_this <> and get shared_ptr <> from shared_from_this ().
Is there another reason why you want shared_ptr <> that doesn't delete anything?
source share