队列的限制大小< T>在C ++中 [英] limit size of Queue<T> in C++

查看:353
本文介绍了队列的限制大小< T>在C ++中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到类似问题的线程:限制队列大小< T>在.NET?
这正是我想做的,但我不是使用.net但GNU C ++。我没有在GNU C ++中的基类的引用,所以java像 super。***()或.net like base。 ()将无法工作。我一直在尝试从队列类继承,但它是徒劳的。

I notice the thread of similar question: Limit size of Queue<T> in .NET? That's exactly what I want to do, but I am not using .net but GNU C++. I have no reference to the base class in GNU C++, so java like super.***() or .net like base.***() will not work. I have been trying to inherit from queue class but it turns out in vain.

我想做什么:
指定队列的大小,并自动队列已满时出列队列。具体来说:如果我的队列的最大大小是2,当我推第三项,第一项将自动弹出之前推新项。

What I want to do: specify the size of the queue, and automatically dequeue when the queue is full. To be specific: if the maximum size of my queue is 2, when I push the 3rd item, the 1st item will be automatically popped out before pushing the new item.

如何实现这样的队列?

感谢。

推荐答案

一个封装队列并在新类中实施大小限制的新类。

Make a new class that encapsulates the queue and enforce a size limit in the new class.

这篇关于队列的限制大小&lt; T&gt;在C ++中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆