Note that there are some explanatory texts on larger screens.

plurals
  1. POSeg faults at particular line, can't figure out why
    primarykey
    data
    text
    <p>The program seg faults once it reaches this line of code (the code is in Graph.cpp in the function set_array.)</p> <pre><code>adjList[adjList.size()].push_back(Edge(vertex, 0)); </code></pre> <p>Basically, I want this line to be called every time i need to make the vector longer to fit more linked lists, as the structure is an vector of linked lists. Here is the .h file that declares the vector of linked lists and its contents. Every node will contain a vertex and a weight. (The node class is known as <code>class Edge</code>.)</p> <pre><code>#ifndef GRAPH_H_INCLUDED #define GRAPH_H_INCLUDED //class MinPriority; #include &lt;iostream&gt; #include &lt;string&gt; #include &lt;vector&gt; #include &lt;list&gt; using namespace std; class Graph { public: Graph(); ~Graph(); void set_Edge(string targetVertex, string vertex, int weight); void set_array(string vertex); void print_Test(); friend class MinPriority; private: class Edge { public: Edge(string vertex, int weight) {m_vertex = vertex; m_weight = weight;} ~Edge(){} string m_vertex; int m_weight; }; vector&lt; list&lt;Edge&gt; &gt; adjList; //declaration of the array of linked lists }; #endif // GRAPH_H_INCLUDED </code></pre> <p>here is what I want <code>adjList[adjList.size()].push_back(Edge(vertex, 0));</code> to do; basically every time I want to insert a new vertex into the graph, I will call this. It seg faults as soon as I try to put the first item in the tree. Ill call to insert 'A' with a weight of '0' and it will immediately seg fault. By the way, I am trying to make an adjacency list where i use <code>adjList[adjList.size()].push_back(Edge(vertex, 0));</code> to add a new (unused) vertex into the graph. Lets pretend this is passed into the function...</p> <pre><code>A B C D </code></pre> <p>After doing this, the vector's length should increase by 4. But of course it instead seg faults at that line (it tells me in GDB). I'm very new to using wierd data structures like this so any help would be very appreciated.</p>
    singulars
    1. This table or related slice is empty.
    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