limit size of Queuelt;Tgt; in C++(队列的限制大小lt;Tgt;在 C++ 中)
问题描述
我注意到类似问题的主题:Limit size of Queue<T>在 .NET 中?这正是我想要做的,但我使用的不是 .net,而是 GNU C++.我没有引用 GNU C++ 中的基类,因此 super.***() 之类的 java 或 base.***() 之类的 .net 将不起作用.我一直在尝试从队列类继承,但结果是徒劳的.
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,当我推送第3个项目时,会在推送新项目之前自动弹出第1个项目.
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.
这篇关于队列的限制大小<T>在 C++ 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:队列的限制大小<T>在 C++ 中
基础教程推荐
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- CString 到 char* 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
