【发布时间】:2016-12-14 16:57:17
【问题描述】:
我创建了这个向量,它有缓冲区:
std::vector<std::unique_ptr<locked_buffer<std::pair<int, std::vector<std::vector<unsigned char>>>>>> v1;
然后,我用n 缓冲区填充这个向量,这个缓冲区有aux 元素。 n 是一个 int 数字,它是一个参数。 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);
谢谢。
【问题讨论】:
-
我认为您需要取消引用
unique_ptr,v1[i]->put...也是如此 -
最后的双向量是否应该是二维矩阵?此外,这将是使用
using的好地方。比如template<class T> using myBufferType = std::pair<int, std::vector<std::vector<T>>>;那么你的类型就是std::unique_ptr<locked_buffer<myBufferType<unsigned char>>>
标签: c++ vector buffer stdvector unique-ptr