在 C++ 中声明队列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19754593/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 23:07:36  来源:igfitidea点击:

Declaring queue in c++

c++queue

提问by zalyahya

I'm trying to declare a queue in c++:

我试图在 C++ 中声明一个队列:

#include <queue>
......
......
queue<Process> *readyQueue = new queue<Process>;
.......

But i keep getting this error

但我不断收到这个错误

'queue' was not declared in this scope

“队列”未在此范围内声明

What am I missing? I, of course, created the Process struct, so the problem isn't there. What's the issue?

我错过了什么?当然,我创建了 Process 结构,所以问题不存在。有什么问题?

回答by klm123

You are missing namespace specification. I suppose you want std functions. Use either:

您缺少命名空间规范。我想你想要 std 函数。使用:

 #include <queue>
 ......
 std::queue<Process> *readyQueue = new std::queue<Process>;

or

或者

 #include <queue>
 using std::queue;
 ......
 queue<Process> *readyQueue = new queue<Process>;

回答by John Dibling

You need to specify the correct namespace

您需要指定正确的命名空间

std::queue

std::queue

回答by Netherwire

You should use using namespace std;or the std::prefix. This might help you:

您应该使用using namespace std;std::前缀。这可能会帮助您:

#include <queue>

int main()
{
    Process p1;
    Process p2;

    std::queue<Process> readyQueue;
    readyQueue.push(p1);
    readyQueue.push(p2);
}

See referencefor more details.

有关更多详细信息,请参阅参考资料