gpt4 book ai didi

c++ - 初始化一个 unique_ptr 数组

转载 作者:行者123 更新时间:2023-11-28 06:30:58 31 4
gpt4 key购买 nike

我正在尝试构建一个实体组件类,该类将组件存储在派生组件指针的 std::arrays of std::unique_ptr 的 vector 中,如下所示:

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 类的问题,还是我这样做完全错误(这是可能的?)

最佳答案

好像是用了emplace_back()跳过 std::pair<...>它真的不应该在哪里。尝试

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

你实际上尝试在 component 中添加一些东西这似乎是一种类型,包含 components 类型的实体.

关于c++ - 初始化一个 unique_ptr 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27585014/

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