shinlin shinlin - 1 year ago 104
C++ Question

creating fixed size queue for c++

I develop code for creating fixed size queue in c++. I am struck in how to extend std::queue to have this functionality. I looked at other similar SO questions, but they don't give a clear example on how to do this.Is there any examples I can refer to on how to do this. Thanks

template<typename T>
class fixed_size_queue: public std::queue<T>
fixed_size_queue(unsigned int size);


void fixed_size_queue::fixed_size_queue(unsigned int size)
this->size()= size;


Answer Source

You shouldn't extend standard containers since it's very unsafe. The better solution is to create your own class and use the std::queue as a class member along with any internal restrictions required for your class.