title: c++ remove vertex from a graph
body: <p>3he following compiles using boost.1.46.1</p>
  
  <pre><code>#include &lt;boost/graph/adjacency_list.hpp&gt;
  
  struct Node {
    int id;
  };
  
  struct Edge {
    int source;
    int target;
    int weight;
  };
  
  int main() {
    /* an adjacency_list like we need it */
    typedef boost::adjacency_list&lt;
      boost::setS, // edge container
      boost::listS, // vertex container
      boost::bidirectionalS, // directed graph
      Node, Edge&gt; Graph;
  
    typedef boost::graph_traits&lt;Graph&gt;::vertex_descriptor Vertex;
  
    Graph gp1;
  
    std::cout &lt;&lt; "Number of vertices 1: " &lt;&lt; boost::num_vertices(gp1) &lt;&lt; std::endl;
    Vertex v1 = boost::add_vertex(gp1);
    Vertex v2 = boost::add_vertex(gp1);
  
    std::cout &lt;&lt; "Number of vertices 2: " &lt;&lt; boost::num_vertices(gp1) &lt;&lt; std::endl;
  
    gp1[v1].id = 3;
    gp1[v2].id = 4;
  
    Graph gp2(gp1);
  
    std::cout &lt;&lt; "Number of vertices 3: " &lt;&lt; boost::num_vertices(gp2) &lt;&lt; std::endl;
  
    boost::remove_vertex(v2, gp2);
  
    std::cout &lt;&lt; "Number of vertices 4: " &lt;&lt; boost::num_vertices(gp1) &lt;&lt; std::endl;
    std::cout &lt;&lt; "Number of vertices 5: " &lt;&lt; boost::num_vertices(gp2) &lt;&lt; std::endl;
  
    boost::graph_traits&lt;Graph&gt;::vertex_iterator it, end;
    for (boost::tie( it, end ) = vertices(gp2); it != end; ++it) {
      if ( gp2[*it].id == 3 ) {
        boost::remove_vertex(*it, gp2);
      }
    }
  
    std::cout &lt;&lt; "Number of vertices 6: " &lt;&lt; boost::num_vertices(gp1) &lt;&lt; std::endl;
    std::cout &lt;&lt; "Number of vertices 7: " &lt;&lt; boost::num_vertices(gp2) &lt;&lt; std::endl;
  
    return 0;
  }
  </code></pre>
  
  <p>How does gp2 know about v2 when removing it at: "boost::remove_vertex(v2, gp2)"
  and why does the number of vertices of gp1 decrease by 1?</p>
  
  <p>Why does it give a segmentation fault at: "boost::remove_vertex(*it, gp2)"
  and how can I fix it?</p>