gpt4 book ai didi

c++ - C++ 中的缓冲区 vector

转载 作者:搜寻专家 更新时间:2023-10-31 00:55:49 24 4
gpt4 key购买 nike

我创建了这个 vector ,它有缓冲区:

std::vector<std::unique_ptr<locked_buffer<std::pair<int, std::vector<std::vector<unsigned char>>>>>> v1;

然后,我用 n 缓冲区填充这个 vector ,这个缓冲区有 aux 元素。 n 是一个整数,它是一个参数。 aux 也是一个 int 类型的参数。

for(int i=0; i<n; i++){
v1.push_back(std::unique_ptr<locked_buffer<std::pair<int,std::vector<std::vector<unsigned char>>>>> (new locked_buffer<std::pair<int, std::vector<std::vector<unsigned char>>>>(aux)));
}

但是当我尝试访问 vector 的每个缓冲区时却无法访问,因为我还不清楚如何访问 vector 结构的特定元素:

v1[0].put(image, false);

我遇到的编译错误如下(put 函数定义在我自定义的 locked_buffer 结构中):

error: ‘_gnu_cxx::_alloc_traits<std::allocator<std::unique_ptr<locked_buffer<std::pair<int, std::vector<std::vector<unsigned char> > > > > > >::value_type {aka class std::unique_ptr<locked_buffer<std::pair<int, std::vector<std::vector<unsigned char> > > > >}’ has no member named ‘put’
v1[i].put(image, false);

谢谢。

最佳答案

v1[0]unique_ptr<locked_buffer<...>> .为了在包含的 locked_buffer 上调用方法,您需要取消引用 unique_ptr ,即

(*v1[0]).put(image, false);

v1[0]->put(image, false);

关于c++ - C++ 中的缓冲区 vector ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41148107/

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