Alex Rivera | Logout

Is there any reason to use auto_ptr?

Asked 2010-12-29T12:40:01.807
16

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 many auto_ptr's pitfalls.

My question is: are there any real life tasks where auto_ptr is really usefull and does fit there well?

Edit
Report

1 Answer

2

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.

answered 2010-12-29T12:43:13.703

Your Answer