我在向队列中插入pair<int, int>
类型的对象时遇到了问题。我得到了一个奇怪的错误,不知道如何解决。有人能帮忙吗?下面是该方法的代码,后跟错误消息。前两个错误是为了插入,最后一个是关于使用operator=
,也需要帮助。谢谢!
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: 错误:模板参数数量错误(应为2,实际为1)
/usr/include/c++/4.4/bits/stl_pair.h:67: 错误:提供了
‘template<class _T1, class _T2> struct std::pair’
hw8.h:190: 错误:模板参数数量错误(应为2,实际为1)
/usr/include/c++/4.4/bits/stl_pair.h:67: 错误:提供了
‘template<class _T1, class _T2> struct std::pair’
hw8.h:200: 错误:没有与
‘operator=’
匹配的函数‘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: 注意:候选函数是:
std::pair<int, int>& std::pair<int, int>::operator=(const std::pair<int, int>&)
hw8.h
文件的第181行是哪一行代码? - Matt Ball