初始化unique_ptrs数组

时间:2014-12-20 22:42:42

标签: c++ arrays c++11 unique-ptr

我正在尝试构建一个实体组件类,它将组件存储在派生组件指针的std :: unique_ptrs的std :: arrays的向量中,如下所示:

vector<pair<int, array<unique_ptr<Component>, 32>>> components;

当尝试为新组件创建新数组时,即使使用move(),我也会收到以下错误:

this->count++;
vector<pair<int, array<unique_ptr<Component>, 32>>> component_set;
this->components.emplace_back(make_pair(this->count, move(component_set)));

    Error   1   error C2248: 'std::unique_ptr<_Ty>::unique_ptr' : 
    cannot access private member declared in class 'std::unique_ptr<_Ty>'   
    c:\program files\microsoft visual studio 11.0\vc\include\array  211 1   
    entity

这是使用std :: array类的问题,还是我这样做完全错了(这可能吗?)

1 个答案:

答案 0 :(得分:1)

似乎emplace_back()的使用跳过了std::pair<...>,它真的不应该。尝试

this->componets.emplace_back(int, std::array<std::unique_ptr<Component>, 32>());

您实际上尝试在component中添加一些内容,它似乎属于包含类型为components的实体。

相关问题