title: Segmentation fault (core dumped) - Two dimensional array
body: <p>I have problem with this code:<br><br></p>
  
  <pre><code>1) Segmentation fault in cpp object.
  </code></pre>
  
  <p>The same code working on <code>main</code> function. </p>
  
  <pre><code>// Create
  vector&lt; vector&lt;int&gt; &gt; vec(4, vector&lt;int&gt;(4));
  // Write
  vec[2][3] = 10;
  // Read
  int a = vec[2][3];
  </code></pre>
  
  <p>I create a two-dimensional array element. There is a problem with memory allocation. I do not know how to handle it.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;    
  using namespace std;
  
  class Matrix
  {
  public:
      int m, n;
      Matrix();
      Matrix(int, int);
      vector&lt;vector&lt;int&gt; &gt; vec;
  };
  
  int main()
  {
      Matrix obj(3, 4);
      obj.vec[1][2] = 33;
      return 0;
  }
  
  Matrix::Matrix()
  {
      n = 0;
      m = 0;
      vector&lt; vector&lt;int&gt; &gt; vec(m, vector&lt;int&gt;(n));
  }
  
  Matrix::Matrix(int m, int n)
  {
      this-&gt;m = m;
      this-&gt;n = n;
      vector&lt; vector&lt;int&gt; &gt; vec(m, vector&lt;int&gt;(n));
  }
  </code></pre>