Segmentation fault when accessing a pointer's member function in a vector
<p>For some reason I'm getting a segmentation fault; I'm using a vector of pointers, which point to a class object. Basically I need a node that has a vector of pointers to other nodes, in other to make a multigraph. Here's the relevant part of my code:</p>

<p><strong>node.h:</strong></p>

<pre><code>#ifndef NODE_H
#define NODE_H

class node
{
public:
    string content()
    vector&lt;node*&gt; next;      //causing the error
    void add_arc(node a);

    string rna_frag;

#endif
</code></pre>

<p><strong>node.cpp:</strong></p>

<pre><code>void node::add_arc(node a)
{
    node *b = &amp;a;    //b-&gt;content() works fine here
    next.push_back(b);
}

string node::content()
{
    return rna_frag;
}
</code></pre>

<p><strong>main.cpp:</strong></p>

<pre><code>int main()
{
    vector&lt;node&gt; nodes;
    node a;
    node b;
    node c;

    a.add_arc(b);
    a.add_arc(c);
    a.rna_string = "G";

    nodes.push_back(a);
    nodes.push_back(b);
    nodes.push_back(c);

    cout &lt;&lt; nodes[0].content() &lt;&lt; endl;    //prints "G", works fine
    cout &lt;&lt; nodes[0].next.size() &lt;&lt; endl;  // prints "2", works fine
    cout &lt;&lt; nodes[0].next[0]-&gt;content() &lt;&lt; endl;  //segmentation fault
    //cout &lt;&lt; nodes[0].next-&gt;content() &lt;&lt; endl;   //also segmentation fault
    //cout &lt;&lt; nodes[0].next[0]-&gt;rna_frag &lt;&lt; endl; //also segmentation fault
}
</code></pre>

<p>in this case, nodes[0]'s string is "G" and is pointing to 2 other nodes, so the first 2 couts are working perfectly. But when I access the vector's contents it just crashes and gives a segmentation fault error. Anyone know why?</p>