i am having trouble inserting objects of type pair<int, int> into a queue. i am getting a strange error, and i have no idea how to go about fixing it. Can anyone help? the following is the code for the method, followed by the error messages. The first two errors are for the insert, the last is for the usage of the operator=, help with that too would be appreciated. Thanks!
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];
}
errors:
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>&)
Lines of code like so:
pairq.push(pair< &whereto->value, &whereto->adj->value >);
should probably look like:
pairq.push(make_pair(whereto->value, whereto->adj->value));
or if the value members aren't of type int:
pairq.push(pair<int,int>(whereto->value, whereto->adj->value));
Finally, queue::pop() doesn't return anything, so you probably want:
tree[i] = pairq.front();
pairq.pop();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With