gpt4 book ai didi

c++ - 为什么 unique_ptr 对 auto_ptr 有重载?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:44:03 25 4
gpt4 key购买 nike

我遇到编译器错误并注意到一些有趣的事情。出于某种原因,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*'

这是因为与使用 auto_ptr 的代码向后兼容吗?

最佳答案

是的,它用于与 auto_ptr 的互操作,并且已弃用(根据标准)

Normative for the current edition of the Standard, but not guaranteed to be part of the Standard in future revisions.

关于c++ - 为什么 unique_ptr 对 auto_ptr 有重载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26073077/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com