title: Unable to initialize and use 2D vector
body: <p>I am trying to create and use a 2D vector of a struct. But things are not working. following is the code snippet I am using.</p>
  
  <pre><code>struct Node 
  {
  int a,b; 
  Node() : a(-1) , b(-1){};
  };      
  int m =5; n=4;    
  vector&lt;vector&lt;Node&gt;&gt;T;
      T.resize(m, vector&lt;Node&gt;(0));
      for (int i = 0; i &lt; m; i++)
         {
            T[i].resize(n, Node());
         }
  </code></pre>
  
  <p>After running this, the vector sizes are correctly initialized but the capacity is incorrect. Specifically T has size = capacity = 5, but all T[i] have size 4 and capacity 1.
  Nonetheless the element values seem to be correctly initialized.
  <a href="http://i.stack.imgur.com/J1t4j.png" rel="nofollow">See here</a>
  Secondly when I try to modify the vector later on I am unable to do so.</p>
  
  <pre><code> for (int i = 0; i &lt; m; i++)
        for (int j = 0; j &lt; n; j++)
        {
          T[i][j].a= -1;
          T[i][j].b= -1;
        }
  </code></pre>
  
  <p>On running this , the first element (T[0][0]) is correctly updated but subsequent iterations are causing random elements to be updated. 
  I am unable to figure out what I am doing wrong.</p>
  
  <p>I tried initializing as</p>
  
  <pre><code>vector&lt;vector&lt;Node&gt;&gt;T(m, vector&lt;Node&gt;(n));
  </code></pre>
  
  <p>But still face the same issue in modifying values.</p>