title: Process exited with return value 3221225477 accessing multi dimensional vector
body: <p>I can't find the problem in a c++ project i'm developing for educational purposes.
  Here i will post my code and explain where I found the problem is (thanks to some debugging), i just can't figure out why this is a problem:</p>
  
  <pre><code>#include &lt;string&gt;
  #include &lt;iostream&gt;
  #include "Matrix.h"
  
  int main() {
      using namespace std;
      cout &lt;&lt; "&lt;--------------- MATRIXES ---------------&gt;\n";
      // Dimensions
      const int HEIGHT = 3;
      const int WIDTH = 4;
      // Multi-dimensional int array
      int A[HEIGHT][WIDTH] = {
          {0, 1, 2, 4},
          {1, 0, 2, 1},
          {1, 1, 5, 8}
      };
      // Multi-dimensional int vector built with data from A
      std::vector&lt;std::vector&lt;int&gt;&gt; Am(HEIGHT);
      for (int i = 0; i &lt; HEIGHT; ++i)
          Am[i].resize(WIDTH);
      for (int i = 0; i &lt; HEIGHT; ++i)
          for (int j = 0; j &lt; WIDTH; ++j)
              Am[i][j] = A[i][j];
      // Everything before this comment works fine
  
      // WORKING constructor for my Matrix
      Matrix&lt;int&gt; M(Am);
  
      // The problem is in the M.toString() call,
      // in the next code block i will explain exatcly where
      cout &lt;&lt; "Matrix M:\n" &lt;&lt; M.toString() &lt;&lt; "\n";
  
      return 0;
  }
  </code></pre>
  
  <p>This is the main.cpp of my project, here is the Matrix.h file:</p>
  
  <pre><code>#include &lt;string&gt;
  #include &lt;vector&gt;
  #include &lt;algorithm&gt;
  #include &lt;iostream&gt;
  #include &lt;cmath&gt;
  
  template &lt;class T&gt;
  class Matrix{
  
      std::vector&lt;std::vector&lt;T&gt; &gt; M;
      int HEIGHT;
      int WIDTH;
  
      public:
          Matrix();
          Matrix(std::vector&lt;std::vector&lt;T&gt; &gt; m) {
              HEIGHT = m.size();
              WIDTH = m[0].size();
              std::vector&lt;std::vector&lt;T&gt; &gt; M(HEIGHT);
              for (int i = 0; i &lt; HEIGHT; ++i)
                  for (int j = 0; j &lt; WIDTH; ++j)
                      M[i].push_back(m[i][j]);
          };
  
          std::string toString() {
  
              std::cout &lt;&lt; M[0][0];
              std::string r = "";
              /*for (int i = 0; i &lt; HEIGHT; ++i) {
                  for (int j = 0; j &lt; WIDTH; ++j) {
                      if (j != WIDTH - 1)
                          r += std::to_string(M[i][j]) + " ";
                  }
                  if (i != HEIGHT - 1)
                      r += "\n";
              }*/
              return r;
          }
  };
  </code></pre>
  
  <p>The code would be larger but i commented everything which is not in this post, as you can see the toString method only prints M[0][0] an returns "", the executions "stops working" exactly at the std::cout &lt;&lt; M[0][0], and i figured out that no matter where but when i try to access the multi dimensional vector M it stops working and it gives me: "Process exited with return value 3221225477".</p>
  
  <p>Any ideas?</p>
  
  <p>PS: I'm working on Windows 10, i have the same issue using clang and dev-c++
  EDIT: It looks like the Matrix gets constructed (I already tested it, it gets constructed properly) but then the program forgets how the matrix is and trying to access it is like trying to access an empty vector... Don't know why..</p>