无效使用Queue和.pop()的void表达式 [英] Invalid use of void expression with a Queue and .pop()
本文介绍了无效使用Queue和.pop()的void表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在努力做到这一点,以便可以将一个队列中的元素弹出到新队列中,并在第一行代码"temp.push(Q.pop());"中继续收到该错误.
I am trying to make it so that I can pop elements from one queue into a new queue and keep getting that error for this first line of code "temp.push(Q.pop());".
这是我所缺少的基本知识,所以可以指出吗?
It is something fundamental I am missing so can it be pointed out?
#include <iostream>
#include <queue>
#include <stack>
using namespace std;
void Halves(queue<int>& Q)
{
stack<int> reverse;
queue<int> temp;
for (int i=0; i < Q.size()/2 ; i++)
{
temp.push(Q.pop());
}
for (int i=0; i < Q.size(); i++)
{
reverse.push(Q.pop());
}
for (int i=0; i < reverse.size(); i++)
{
Q.push(reverse.pop());
}
for (int i=0; i < temp.size(); i++)
{
Q.push(temp.pop());
}
copy(Q);
}
推荐答案
std :: queue :: pop()
是 void
.因此,您不能使用:
The return type of std::queue::pop()
is void
. Hence, you may not use:
reverse.push(Q.pop());
您可以使用:
reverse.push(Q.front());
Q.pop();
这篇关于无效使用Queue和.pop()的void表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文