Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ standard template library priority queue throws exception with message "Invalid Heap"
    text
    copied!<p>Using the STL's <code>priority_queue</code> I get the error "invalid heap" as soon as I try to use <code>pop()</code>. I can push my values into the queue, the <code>top()</code> of the queue is what I would expect and accessible. <code>pop()</code>, when it goes to re-heap, seems to have a problem.</p> <p>I am storing pointers to a templated class in the queue. I have the comparision overloaded:</p> <pre><code>template &lt;class type&gt; class vertexPriorityCompare { public: bool operator()(Vertex&lt;type&gt;* leftVertex, Vertex&lt;type&gt;* rightVertex) const { if(leftVertex-&gt;getDistanceFromSource() &lt; 0 &amp;&amp; rightVertex-&gt;getDistanceFromSource() &lt; 0) { return false; } else if(leftVertex-&gt;getDistanceFromSource() &lt; 0) { return true; } else if(rightVertex-&gt;getDistanceFromSource() &lt; 0) { return false; } else { return leftVertex-&gt;getDistanceFromSource() &gt; rightVertex-&gt;getDistanceFromSource(); } } }; </code></pre> <p>The <code>priority_queue</code> is a private member of a class:</p> <pre><code>priority_queue&lt; Vertex&lt;type&gt;*, vector&lt; Vertex&lt;type&gt;* &gt;, vertexPriorityCompare&lt;type&gt; &gt; Q; </code></pre> <p>The overload works in the fashion it does, because a negative distance is considered infinity, always larger than whatever else; to represent infinity, distances are initialized to -1. The queue needs to keep the smallest, but non-negative at the top.</p> <p>I dereference the pointers in the overload, is what I'm doing there allowable? And, is there another operator I need to overload?</p> <p>I would attach code, but it seems if I do, it scares people away. Request to see more and I'll attach to another message.</p> <p>I dynamically declare an array of pointers to pointers, these are what get pushed, because I assume <code>priority_queue</code> stores by reference, so if I just put a pointer declared in the loop into the queue, that pointer goes out of scope. These pointers point to the proper <code>Vertex&lt;type&gt;</code>, and exist throughout the function.</p> <p>Visual Studio 2008 debugger takes me into 'stdthrow.cpp' line 24.</p>
 

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