Vector of buffers in C++

944 views Asked by At

I've created this vector, which has buffers:

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

Then, I fill this vector with n buffers and this buffers have aux elements. n is an int number which is an argument. auxis another argument that is an int type too.

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

But when I try to access to each buffer of the vector I can't, because I haven't got clear how can I access to a specific element of a vector structure:

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

The compilation error that I've got is the following one (The put function is defined on my custom locked_buffer structure):

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

Thanks.

1

There are 1 answers

0
jsb On BEST ANSWER

v1[0] is a unique_ptr<locked_buffer<...>>. In order to call a method on the contained locked_buffer, you need to dereference the unique_ptr, i.e.

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

or

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