Defining a que with exacly 5 elements

I went through the library <queue> standard library. When we want to initialize a queue using that we use the follwing code segmant.

queue<string> q;

But there is no parameter accepting the number of elements in a queue. So i think the above definition is for dynamic arrays (queue).

I want to define a queue which exactly has 5 elements. How can i de it?
In queue in std there is no such ability.
But of course you can implement your own class by the following way
1
2
3
4
5
6
7
8
9
10
template <typename T>
class Queue
{
public:
    Queue(unsigned maxSize);
    Queue();
......//other methods
private:
    std::queue<T> m_queue;
};
You cannot force the queue container to have a maximum of 5 elements. But, you can achieve that goal
if you create a wrapper class as Denis suggested.
Topic archived. No new replies allowed.