title: Merging vector of vectors
body: <p>My class is</p>
  
  <pre><code>    class aMatrix {
  private:
      std::vector&lt;std::vector&lt;double&gt; &gt; mat;
      unsigned rows;
      unsigned cols; ...}
  </code></pre>
  
  <p>I want to merge two matrixes using method</p>
  
  <pre><code>aMatrix aMatrix::merge(const aMatrix&amp; ob){
      this-&gt;mat.reserve(this-&gt;mat.size()+ob.mat.size());
      this-&gt;cols+=ob.cols;
      this-&gt;mat.insert(this-&gt;mat.end(), ob.mat.begin(),ob.mat.end());
      return *this;
  }
  </code></pre>
  
  <p>but it doesnt work. 
  Any ideas how to make it work?</p>
  
  <p>edit: there's no error. it just adds column of ~0 and then values than differ from ob.mat.</p>
  
  <p>edit:</p>
  
  <pre><code>aMatrix mat1(3,3);
  mat1(0, 0) = 1;
  mat1(0, 1) = 1;
  mat1(0, 2) = 1;
  mat1(1, 0) = 2;
  mat1(1, 1) = 3;
  mat1(1, 2) = 5;
  mat1(2, 0) = 11;
  mat1(2, 1) = 0;
  mat1(2, 2) = 5;
  aMatrix ones(3,3);
  ones(0,0)=1;
  ones(1,1)=1;
  ones(2,2)=1;
  
  mat1.merge(ones);
  </code></pre>
  
  <p>the result is:</p>
  
  <pre><code>1, 1, 1, 1.11319e-308, 2, 3, 
  2, 3, 5, 1.11318e-308, 11, 0, 
  11, 0, 5, 1.11317e-308, 1, 0, 
  </code></pre>
  
  <p>edit:
  How to make it work in such notation?</p>
  
  <pre><code>// Parameter Constructor
  aMatrix::aMatrix(unsigned _rows, unsigned _cols, const double&amp; _initial) {
      mat.resize(_rows);
      for (unsigned i = 0; i &lt; mat.size(); i++) {
          mat[i].resize(_cols, _initial);
      }
      rows = _rows;
      cols = _cols;
  }
  </code></pre>
  
  <p>edit: OK, it works now. right code:</p>
  
  <pre><code>aMatrix&amp; aMatrix::merge(const aMatrix&amp; ob){
  this-&gt;mat.reserve(this-&gt;mat.size()+ob.mat.size());
  this-&gt;cols+=ob.cols;
  for (unsigned i = 0; i &lt; this-&gt;mat.size(); i++) {
      this-&gt;mat[i].insert(this-&gt;mat[i].end(), ob.mat[i].begin(),ob.mat[i].end() );
  }
  return *this;
  }
  </code></pre>
  
  <p>thanks :)</p>