4

I'm trying to implement a circular buffer for an assignment. To save time, I want to use a deque inside my reorder buffer class. Here's my first attempt at writing a class that contains a deque.

#ifndef ROB_H_
#define ROB_H_

#include <deque>
#include <cstdio>

using namespace std;

class ReorderBuffer{
    public:
        ReorderBuffer (int size);
        void doStuff();

        std::deque<int> buffer;
};    

ReorderBuffer::ReorderBuffer (int size){
    std::deque<int> buffer(size);
}

void ReorderBuffer::doStuff(){

    std::deque<int> buffer(4);

    buffer.push_back(5);
    buffer.push_front(2);
    buffer.push_back(3);
    buffer.push_back(4);
    printf("%d %d\n",buffer.at(0),buffer.pop_front());

}


#endif

In main, I make a reorder buffer with size 4 and call doStuff(). When I try to compile, it says invalid use of void expression. I have narrowed the error down to my call of buffer.pop_front(). Why is it complaining, and what is the best way to put a deque in my class? Thanks!

1 Answer 1

5

std::deque::pop_front returns void. You cannot print this with the result of this function. Use at() to get values and then use pop_front or pop_back to simply remove the front or back element as needed, but note that they do not return anything.

http://en.cppreference.com/w/cpp/container/deque/pop_front

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! That's exactly what I needed to know. Shoulda seen it earlier.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.