Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to insert pair<int, int> into queue?
    text
    copied!<p>i am having trouble inserting objects of type <code>pair&lt;int, int&gt;</code> 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 <code>operator=</code>, help with that too would be appreciated. Thanks!</p> <pre><code>pair&lt;int,int&gt;* bfSpanningTree(int theVertex) { queue&lt; pair&lt;int,int&gt; &gt; pairq; queue&lt;int&gt; nodeq; if(linkedAdjacencyList[theVertex]-&gt;value == theVertex &amp;&amp; linkedAdjacencyList[theVertex]-&gt;adj != NULL) { Node* whereto; whereto = linkedAdjacencyList[theVertex]-&gt;adj; while(whereto-&gt;adj != NULL) { pairq.push(pair&lt; &amp;whereto-&gt;value, &amp;whereto-&gt;adj-&gt;value &gt;); nodeq.push(whereto-&gt;value); whereto = whereto-&gt;adj; } while(!nodeq.empty()) { whereto = linkedAdjacencyList[theVertex]-&gt;adj; while(whereto-&gt;adj != NULL) { pairq.push(pair&lt;&amp;whereto-&gt;value, &amp;whereto-&gt;adj-&gt;value&gt;); whereto = whereto-&gt;adj; } } } int i = 0; pair&lt;int,int&gt;* retVal; pair&lt;int,int&gt; tree[pairq.size()]; while(!pairq.empty()) { tree[i] = pairq.pop(); i++; } retVal = tree; return retVal; } ~UndirectedGraph() { for (int i = 0; i &lt; numVerticies; i++) delete[] linkedAdjacencyList[i]; } </code></pre> <p>errors:</p> <blockquote> <p>hw8.h:181: error: wrong number of template arguments (1, should be 2)</p> <p>/usr/include/c++/4.4/bits/stl_pair.h:67: error: provided for <code>‘template&lt;class _T1, class _T2&gt; struct std::pair’</code></p> <p>hw8.h:190: error: wrong number of template arguments (1, should be 2)</p> <p>/usr/include/c++/4.4/bits/stl_pair.h:67: error: provided for <code>‘template&lt;class _T1, class _T2&gt; struct std::pair’</code></p> <p>hw8.h:200: error: no match for <code>‘operator=’</code> in <code>‘tree[i] = pairq.std::queue&lt;_Tp, _Sequence&gt;::pop [with _Tp = std::pair&lt;int, int&gt;, _Sequence = std::deque&lt;std::pair&lt;int, int&gt;, std::allocator&lt;std::pair&lt;int, int&gt; &gt; &gt;]()’</code></p> <p>/usr/include/c++/4.4/bits/stl_pair.h:68: note: candidates are: <code>std::pair&lt;int, int&gt;&amp; std::pair&lt;int, int&gt;::operator=(const std::pair&lt;int, int&gt;&amp;)</code></p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload