title: Constructor for a class containing a vec of vecs
body: <p>I'm trying to learn how to create a class which properly initializes a vectors of vectors to implement a matrix. The code below doesn't work, after running the constructor the vector has size 0. The program prints 0 and attempts to access elements of it result in errors. </p>
  
  <ol>
  <li>My first question is what is wrong with the code and how to fix it. </li>
  <li>My second question is if there is a better approach to creating a class to implement a matrix dynamically using vectors or similar objects from the STL.</li>
  </ol>
  
  <p>Code:</p>
  
  <pre><code>class Matrix{
      std::vector&lt;std::vector&lt;int&gt; &gt; Mat;
  public:
      Matrix(int n, int m);
      void set(int a, int b, int Value);
      int get(int a, int b);
      void size();
  };
  
  Matrix::Matrix(int n, int m){
      std::vector&lt;std::vector&lt;int&gt; &gt; Mat(n, vector&lt;int&gt;(m));
  }
  
  void Matrix::size(){
      std::cout &lt;&lt; std::endl &lt;&lt; Mat.size() &lt;&lt; std::endl;
  }
  
  int Matrix::get(int a, int b){
  return Mat[a][b];
  }
  
  void Matrix::set(int a, int b, int Value){
      Mat[a][b]=Value;
  }
  
  
  int main(int argc, char** argv) {
  
    Matrix M(10,10);
    M.size();  
  
      return 0;
  }
  </code></pre>