Is there any reason to use auto_ptr?

前端 未结 4 1189
一生所求
一生所求 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:42

    I would say it can be used, but it is not the best option.

    First, it is a matter of year or less and auto_ptr is officially deprecated. Second, there is a superior alternative: unique_ptr. Dr. Stroustrup once said about unique_ptr:

    “What auto_ptr should have been” (but that we couldn't write in C++98)

    So unless you don't have the choice, auto_ptr is not a good choice. Mainly, because most C++ compilers these days implement move semantics and provide unique_ptr.

提交回复
热议问题