Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to make a vector of pointers
    primarykey
    data
    text
    <p>For the last two or three hours I have been wrestling with this problem without any luck. I am reading in the text and then trying to make an adjacency list with all vertices having a link to the adjacent vertices in the list. The vertex class look like this:</p> <pre><code>class Vertex { private: std::vector&lt;Vertex*&gt; connPtrVertices; // vector of vertices adjacent to this one public: void addVertex(Vertex* vert) { connPtrVertices.push_back(vert); } </code></pre> <p>And in main.cpp I am trying to connect the vertices to each other like this: </p> <pre><code>Vertex *v1, *v2; v2-&gt;addVertex(v1); // connect v2 to v1 v1-&gt;addVertex(v2); // connect v1 to v2 </code></pre> <p>I am getting a Debug Assertion Failed message which is:</p> <pre><code>Debug Assertion Failed! Program: C:\Windows\system32\MSVCP110D.dll File: c:\program files (x86)\microsoft visual studio 11.0\vc\include\vector Line: 240 Expression: vector iterators incompatible </code></pre> <p>I have no clue what to do, any help will be greatly appreciated.</p> <p>Edit: The first time through the loop I am assigning v1 and v2 with new but then the second time I check if they exist and if they do I assign a pointer to Vertex like this:</p> <pre><code>v1 = &amp;(p_graph-&gt;getVertex(vert1)); </code></pre> <p>The method that is called is this:</p> <pre><code>Vertex Graph::getVertex(std::string v) { // gets the vertex for (std::vector&lt;Vertex&gt;::iterator it = vertices.begin(); it != vertices.end(); it++) { if ((it-&gt;getName()).compare(v) == 0) return *it; // if strings are the same return vertex } exit(1); } </code></pre> <p>Is this where the mistake is?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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