我无法将pair<int, int>
类型的对象插入到队列中。我收到一个奇怪的错误,我不知道如何去解决它。谁能帮忙?以下是该方法的代码,然后是错误消息。前两个错误是为插入,最后是为operator=
的使用,帮助与此也将不胜感激。谢谢!如何将队列<int, int>插入队列?
pair<int,int>* bfSpanningTree(int theVertex)
{
queue< pair<int,int> > pairq;
queue<int> nodeq;
if(linkedAdjacencyList[theVertex]->value == theVertex && linkedAdjacencyList[theVertex]->adj != NULL)
{
Node* whereto;
whereto = linkedAdjacencyList[theVertex]->adj;
while(whereto->adj != NULL)
{
pairq.push(pair< &whereto->value, &whereto->adj->value >);
nodeq.push(whereto->value);
whereto = whereto->adj;
}
while(!nodeq.empty())
{
whereto = linkedAdjacencyList[theVertex]->adj;
while(whereto->adj != NULL)
{
pairq.push(pair<&whereto->value, &whereto->adj->value>);
whereto = whereto->adj;
}
}
}
int i = 0;
pair<int,int>* retVal;
pair<int,int> tree[pairq.size()];
while(!pairq.empty())
{
tree[i] = pairq.pop();
i++;
}
retVal = tree;
return retVal;
}
~UndirectedGraph()
{
for (int i = 0; i < numVerticies; i++)
delete[] linkedAdjacencyList[i];
}
错误:
的代码hw8.h:181: error: wrong number of template arguments (1, should be 2)
/usr/include/c++/4.4/bits/stl_pair.h:67: error: provided for
‘template<class _T1, class _T2> struct std::pair’
hw8.h:190: error: wrong number of template arguments (1, should be 2)
/usr/include/c++/4.4/bits/stl_pair.h:67: error: provided for
‘template<class _T1, class _T2> struct std::pair’
hw8.h:200: error: no match for
‘operator=’
in‘tree[i] = pairq.std::queue<_Tp, _Sequence>::pop [with _Tp = std::pair<int, int>, _Sequence = std::deque<std::pair<int, int>, std::allocator<std::pair<int, int> > >]()’
/usr/include/c++/4.4/bits/stl_pair.h:68: note: candidates are:
std::pair<int, int>& std::pair<int, int>::operator=(const std::pair<int, int>&)
哪行代码在'hw8.h'行181? – 2011-04-13 02:11:38