Intialize circular buffer of Boost Library as member class Linux

  • Hello guys i am struggling trying to initialize the size of a circular buffer as member class

    searching at Google i found another user asking how to do it. The number 3 must be the size of the buffer

    class example {
      boost::circular_buffer<int> aspBuffer;
      example() : aspBuffer(3) {}

    i am trying to do the same but not successful, Take a look at my header

    #include <QObject> //To use the class as an Object
    #include <boost/circular_buffer.hpp>
    class backend: public QObject
        //---------------------------PUBLIC VARIABLES BACKEND BEGIN---------------------
        boost::circular_buffer<unsigned char> circular_buff();     //buffer to hold the stream data
        //---------------------------PUBLIC VARIABLES BACKEND END-----------------------
        //---------------------------PUBLIC BACKEND FUNCTIONS BEGIN---------------------
        backend() : circular_buff(100);
        //---------------------------PUBLIC BACKEND FUNCTIONS END-----------------------

    Compiler shows

    /home/pasante/Escritorio/PIZZA/backend.h:21: error: class ‘backend’ does not have any field named ‘circular_buff’
         backend() : circular_buff(100);

    I am thinking maybe is a bad linking in the .pro file

    I installed the lib boost through

    sudo apt-get install libboost-all-dev

    my .pro file

    LIBS += -lboost_system\

    but when i wtire #include <boos the autocomplete show me the path to <boost/circular_buffer.hpp>

    I am not sure what i am doing wrong

    Example of initiliazation as not member class

       #include <boost/circular_buffer.hpp>
       int main() {
          // Create a circular buffer with a capacity for 3 integers.
          boost::circular_buffer<int> cb(3);

  • boost::circular_buffer<unsigned char> circular_buff(); //buffer to hold the stream data

    this is a method declaration, not a member, get rid of () and you are done

    boost::circular_buffer<unsigned char> circular_buff;     //buffer to hold the stream data

    don't declare it public, please

  • Really thanks!!!!!!!!!!

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.