title: Header file about 'directed graphs' gives a Segmentation Fault
body: <p>I use Code::Blocks and am trying to implement a header file that has 'graph' related methods like creating an adjacency list and printing them. But unfortunately, it gives a segmentation fault.</p>
  
  <p>I use 'Vector of vectors' for my adjacency lists. Now weirdly Code::Blocks doesn't give any warnings or errors when I compile my code(nor does it work) but another compiler gives a segmentation fault.  </p>
  
  <p>(P.S. I know I should only prototype methods in my header file and use a separate source file to write them out but it's not working for some reason. Please bear with me)</p>
  
  <p>Meat of my header file: (omitted the includes and namespace to be concise)</p>
  
  <pre><code>struct Edge{
      int src,dest;
  };
  
  class Graph{
      public:
          vector&lt;vector&lt;int&gt;&gt; adjList;
          int V,E;
          Graph(int,int);
          void dirGraph(vector&lt;Edge&gt; edges);
          void printGraph();
  };
  
  Graph::Graph(int V,int E)
  {
      this-&gt;V = V;
      this-&gt;E = E;
  }
  
  void Graph::dirGraph(vector&lt;Edge&gt; edges)
  {
      adjList.resize(V);
      for(auto edge:edges){
          adjList[edge.src].push_back(edge.dest);
      }
  }
  
  void Graph::printGraph(){
      for(int i=0 ; i&lt;V ; ++i){
          cout &lt;&lt; i;
          for(auto x:adjList[i]){
              cout &lt;&lt; " -&gt; " &lt;&lt; x;
          }
          cout &lt;&lt; endl;
      }
  }
  
  </code></pre>
  
  <p>Main File:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include "Graph.h"
  
  using namespace std;
  
  int main(){
      vector&lt;Edge&gt; edges =
      {
        {0,1},{1,2},{2,0},{2,1},{3,2},{4,5},{5,4}
      };
      Graph g1(5,7);
      g1.dirGraph(edges);
      g1.printGraph();
      return 0;
  }
  </code></pre>
  
  <p>It should print the directed graph but it does nothing. (Code::Blocks gives 0 warnings and 0 errors. A separate online compiler gave the seg fault. But the  code doesn't work)</p>
  
  <p>Edit: Someone asked for the includes, here they are:</p>
  
  <pre><code>#ifndef GRAPH_H_INCLUDED
  #define GRAPH_H_INCLUDED
  #include &lt;vector&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  //my header file code
  
  #endif
  </code></pre>