2013-12-19 82 views
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的工具集的错误吗?

+0

[Works with GCC。](http://ideone.com/LWj8P9) –

+1

似乎是一个错误。我在VC 2010中遇到了同样的错误,但它与VC 2012一起工作良好。 – ComicSansMS

+0

@ComicSansMS:如果您的评论是答案,我会接受它作为此问题的接受答案。 – dalle

回答

2

似乎是一个错误。

我得到同样的错误,你在2010年VC,但它正常工作与VC 2012

我不是在跟踪标准的变化也不错,但似乎这个功能只添加到与N3073标准(请参阅该页面上的更改10.),这会延迟VC 2010的发布时间。

相关问题