How to get element from circular_buffer

女生的网名这么多〃 提交于 2019-12-09 07:51:48

问题


I am using boost library in MAC (xcode). I have two questions about boost::circular_buffer.

1 - I am getting syntax error when declaring the circular_buffer

boost::circular_buffer<int> cb(10);

Expected parameter decelerator
Expected ')'

2 - Second question is when I add element into boost::circular_buffer using push_back, how to extract / get the element from circular_buffer, pop_front does not give the element.


回答1:


boost::circular_buffer<T>::front() gives you a reference to the element at the "front", while boost::circular_buffer<T>::pop_front() will remove that element.

boost::circular_buffer<T>::back() gives you a reference to the element at the back, while boost::circular_buffer<T>::pop_back() removes that element.

It appears your syntax error is resulting from the most vexing parse. Try instead:

boost::circular_buffer<int> cb;
cb.set_capacity(10); 

Or more succinctly:

boost::circular_buffer<int> cb((10));


来源:https://stackoverflow.com/questions/21760121/how-to-get-element-from-circular-buffer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!