title: STL List to hold structure pointers
body: <p>I have a structure called vertex and I created some pointers to them.  What I want to do is add those pointers to a list.  My code below, when it tries to insert the pointer into the list, creates a segmentation fault.  Can someone please explain what is going on?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;list&gt;
  
  #define NUM_VERTICES 8
  
  using namespace std;
  
  enum { WHITE, GRAY, BLACK };
  
  struct vertex
  {
      int color;
      int distance;
      char parent;
  };
  
  int main()
  {
      //create the vertices
      vertex r = {WHITE, NULL, NULL};
  
      //create pointer to the vertex structures
      vertex *pr = &amp;r;
  
      //create a list to hold the vertices
      list&lt;vertex*&gt; *r_list = new list&lt;vertex*&gt;;
  
      list&lt;vertex*&gt;::iterator it;
  
      r_list-&gt;insert(it, pr);
  }
  </code></pre>