2016-12-14 100 views
2

我創建這種載體,其具有緩衝器:向量的C++

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

感謝。

+1

我認爲你需要取消引用'unique_ptr',所以做'V1 [我] - > put ...' – yassin

+0

最後的雙向量應該是2d矩陣嗎?此外,這將是使用'使用'的好地方。例如'template using myBufferType = std :: pair >>;'然後你的類型是'std :: unique_ptr >>' – RyanP

回答

4

v1[0]unique_ptr<locked_buffer<...>>。爲了調用一個方法上載locked_buffer,您需要取消引用unique_ptr,即

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

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