Is there any reason to use auto_ptr?

前端 未结 4 1158
一生所求
一生所求 2021-01-08 00:24

After reading Jossutis\' explanation on auto_ptr from his STL book I\'ve got a strong impression that whatever task I would try to use it in I\'d 100% fail becuase of one of

4条回答
  •  醉梦人生
    2021-01-08 00:58

    In simple scenarios when you need to temporarily control a heap-allocated object auto_ptr can be used without problems. For example if you need to conditionally create an object that will be used only within one function you can't allocate it on stack and auto_ptr lets you not care of the object lifetime should an exception occur.

提交回复
热议问题