C++ 中的缓冲区向量

Vector of buffers in C++

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

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

然后,我用 n 个缓冲区填充这个向量,这个缓冲区有 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)));  
}

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

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);