title: Dynamically initializing and working with an array of C++ STL list
body: <p>I have a class in which I have declared the array of list as a data member.</p>
  
  <pre><code>list &lt;int&gt; **listOfNodes;
  </code></pre>
  
  <p>I have allocated space for the pointers to lists in the constructor of the class as follows (here 'v' is the no. of lists I want, passed to the constructor as an argument.)</p>
  
  <pre><code>listOfNodes=new list&lt;int&gt;* [v];
  for (int i = 0; i &lt; v; ++i)
  {
      list&lt;int&gt; temp;
      listOfNodes[i]=&amp;temp;  //declaring a new list and making the list pointer point to it
  }
  </code></pre>
  
  <p>Now I have the following code inside the function for taking the input from the user and adding it to the corresponding list. For example, if user enters 2 5, I need to push_back a new entry 5 into the list with index 2, i.e, the list pointed to by listOfNodes[2].</p>
  
  <pre><code>int u,v;
  cin&gt;&gt;u&gt;&gt;v;
  (*(listOfNodes[u])).push_back(v);
  </code></pre>
  
  <p>But, somehow my code crashes on execution.
  Can someone please point out what I might be doing wrong.</p>