0

I had to use a fixed size queue, which is limited to 5 elements. Here is a code, in which I tried to encapsulate the implementation.

typedef enum result{SUCCESS = 1,FAILURE = 0} Result;

class VehicleParcelQueue::public std::queue<Parcel&>{
    public:
        Result push_back(Parcel&){
            if (size() >= 5) return FAILURE;
            else{
                std::queue<Parcel&>::push_back(Parcel&);
                return SUCCESS;
            }
        }
    };

from some reason I'm getting the following error:

error: forming pointer to reference type 'Parcel&'

(Parcel is a class I implemented elsewhere)

What am I doing wrong?

thanks

[edit: I looked in the suggested question, but if I change it to:

class VehicleParcelQueue::public std::queue<Parcel*>{
    public:
        Result push_back(Parcel*){
            if (size() >= 5) return FAILURE;
            else{
                std::queue<Parcel*>::push_back(Parcel*);
                return SUCCESS;
            }
        }
    };

I still get the same error.

Day_Dreamer
  • 3,311
  • 7
  • 34
  • 61
  • 7
    [For the same reason as this question](https://stackoverflow.com/q/922360/440302), you can't create a queue of references. – Rufflewind Jan 14 '15 at 21:58
  • You probably want to pass the parameter to `push_back` as `const Parcel&` and store it in a `std::queue`. – Drew Dormann Jan 14 '15 at 22:06
  • does the effect will be that queue will hold pointer to a copy of Parcel object or to the object Parcle& poins to? – Day_Dreamer Jan 14 '15 at 22:08

0 Answers0