2014-04-01 72 views
0

当我宣布的unique_ptr的一个载体,我得到这样的错误:的std ::向量<性病::的unique_ptr <int>>不编译

d:\qt\mingw64\include\c++\4.8.0\bits\stl_construct.h:75: error: 
use of deleted function 'std::unique_ptr<_Tp, _Dp>::unique_ptr(
const std::unique_ptr<_Tp, _Dp>&) [with _Tp = int; _Dp = std::default_delete<int>]' 

,它看起来像创建的容器的经典错误没有拷贝构造函数的对象。

但是,在所有我能找到的标准unique_ptrs容器工作归功于C++ 11移动语义。

我正在用MinGW-gcc 64位编译,使用-std = gnu ++ 11。

仅支持C++ 11而不支持gnu ++ 11吗?

谢谢

+1

为什么不尝试使用C++ 11? – juanchopanza

+0

'4.8.0'它不符合C + 11,任何从'4.8.1'开始的发布都是 – user2485710

+1

请看以下链接:http://stackoverflow.com/q/10613126/2724703 –

回答

1

问题不是std::vector<std::unique_ptr<int> >本身,而是这种类型的成员变量在可复制类中声明。由于该类的默认拷贝构造函数调用了std :: vector的拷贝构造函数,std :: vector又调用std :: unique_ptr的默认构造函数,后者被删除,编译失败。

std::vector<std::unique_ptr<int> >作为函数中的局部变量编译得很好。

2

以下将用C++ 11进行编译。

#include <iostream> 
#include <vector> 
#include <memory> 
using namespace std; 

int main() 
{ 
    std::vector<std::unique_ptr<int> > asdf; 
    return 0; 
} 
相关问题