title: Declaring Dynamic 2D Vector in class
body: <p>We're trying to use a 2D vector because we want a 2D array that will grow dynamically.</p>
  
  <p>We tried this:
  In the class declaration:</p>
  
  <pre><code>    vector&lt;vector&lt;double&gt; &gt; table;
  </code></pre>
  
  <p>But then table doesn't seem to be allocated. We get a segfault when we try to access members.</p>
  
  <p>So then we tried this:</p>
  
  <p>Class Declaration:</p>
  
  <pre><code>    vector&lt;vector&lt;double&gt; &gt;* table;
  </code></pre>
  
  <p>Constructor:</p>
  
  <pre><code>     table = new vector&lt;vector&lt;double&gt; &gt;;
  </code></pre>
  
  <p>But now we the way we accessed it before (with [][]) doesn't work. </p>
  
  <p>We tried a dummy class with this:</p>
  
  <pre><code>class myClass {
      public:
      myClass();
      ~myClass();
      vector&lt;vector&lt;double&gt; &gt; t;
   };
  
  myClass::myClass() 
  {
      t = vector&lt;vector&lt;double&gt; &gt; (10, vector&lt;double&gt;(10));
  }
  </code></pre>
  
  <p>But it wouldn't free properly and we got core dumps. Also when we tried to grow the array, we'd have expclitly construct each new row. </p>
  
  <p>Ex:</p>
  
  <pre><code>t[50] = vector&lt;double&gt;(5);
  t[50][10] = 10;
  </code></pre>
  
  <p>If we didn't do it like this, we'd get a segfault</p>