简体   繁体   English

为什么unique_ptr有auto_ptr的重载?

[英]Why does unique_ptr have an overload for auto_ptr?

I got a compiler error and noticed something interesting. 我收到编译错误,发现有趣的东西。 For some reason unique_ptr has an overload for auto_ptr , but I thought auto_ptr was deprecated: 由于某种原因, unique_ptrauto_ptr的重载,但我认为auto_ptr已被弃用:

/usr/local/include/c++/4.9.0/bits/unique_ptr.h:228:2: 
note:template<class _Up, class> 
std::unique_ptr<_Tp, _Dp>::unique_ptr(std::auto_ptr<_Up>&&)
  unique_ptr(auto_ptr<_Up>&& __u) noexcept;

/usr/local/include/c++/4.9.0/bits/unique_ptr.h:228:2: 
note: template argument deduction/substitution failed:
main.cpp:41:67: note:  mismatched types 'std::auto_ptr<T>' and 'char*'

Is this because of backwards compatibility with code that used auto_ptr ? 这是因为与使用auto_ptr代码向后兼容吗?

Yes, it's for interop with auto_ptr, and deprecated means (according to the standard) 是的,它是与auto_ptr互操作,并且已弃用的手段(根据标准)

Normative for the current edition of the Standard, but not guaranteed to be part of the Standard in future revisions. 当前版本标准的规范性,但不保证在未来的修订版中成为标准的一部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM