0
根据cppreference.com,下面的代码应该可以编译和工作。它应该构建一个unique_ptr
,其中存储的指针用ap.release()
进行初始化,并且存储的删除器将进行值初始化。std :: unique_ptr std :: auto_ptr的转换构造函数
#include <memory>
int main()
{
std::auto_ptr<int> ap(new int());
std::unique_ptr<int> up(std::move(ap));
}
当我编译它(使用VS2013与VS2010工具集),我收到以下错误:
test.cpp(5): error C2664: 'std::unique_ptr<_Ty>::unique_ptr(std::nullptr_t)' :
cannot convert parameter 1 from 'std::auto_ptr<_Ty>' to 'std::nullptr_t'
with
[
_Ty=int
]
nullptr can only be converted to pointer or handle types
这是编译器Visual Studio 2010的工具集的错误吗?
[Works with GCC。](http://ideone.com/LWj8P9) –
似乎是一个错误。我在VC 2010中遇到了同样的错误,但它与VC 2012一起工作良好。 – ComicSansMS
@ComicSansMS:如果您的评论是答案,我会接受它作为此问题的接受答案。 – dalle