title: Vector size() returning seemingly random large integers
body: <p>I am working on a program for homework and ran into a strange problem. When trying to get the size of a 2D vector using the size() function, I get seemingly random large integers which stop my program from running. I need the size to access elements in the vector.</p>
  
  <p>My header file:</p>
  
  <pre><code>#ifndef _MATRIX_H
  #define _MATRIX_H
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  class Matrix {
  
      private:
          //int dimension;
  
          std::vector&lt; std::vector&lt;int&gt; &gt; matrix;
  
      public:
  
          Matrix();
  
          Matrix(std::vector&lt; std::vector&lt;int&gt; &gt;);
  
          void print();
  
          Matrix operator-(Matrix operand);
  
  };
  
  #endif
  </code></pre>
  
  <p>My implementation file:</p>
  
  <pre><code>#include "Matrix.h"
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  // Default constructor
  Matrix::Matrix() {
  
  }
  
  // Parameterized constructor
  Matrix::Matrix(std::vector&lt; std::vector&lt;int&gt; &gt;) {
  
  }
  
  void Matrix::print() {
      std::cout &lt;&lt; "Size of matrix in print() " &lt;&lt; matrix.size() &lt;&lt; std::endl;
      for (int i = 0; i &lt; matrix.size(); i++) {
          for (int j = 0; j &lt; matrix.size(); j++) {
                  std::cout &lt;&lt; matrix[i][j] &lt;&lt; " ";
          }
          std::cout &lt;&lt; std::endl;
      }
  }
  
  Matrix Matrix::operator-(Matrix operand) {
  
      Matrix difference;
      std::vector&lt; std::vector&lt;int&gt; &gt; diffMatrix;
  
      diffMatrix.resize(matrix.size());
  
      for (int i = 0; i &lt; matrix.size(); i++ ) {
          diffMatrix[i].resize(matrix.size());
      }
  
      difference.matrix = diffMatrix;
      if (operand.matrix.size() == matrix.size()) {
  
          for (int i = 0; i &lt; operand.matrix.size(); i++) {
              for (int j = 0; j &lt; operand.matrix.size(); j++) {
                  difference.matrix[i][j] = matrix[i][j] - operand.matrix[i][j];
              }
          }   
      } 
  }
  </code></pre>
  
  <p>and my main.cpp file:</p>
  
  <pre><code>#include "Matrix.h"
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  using namespace std;
  
  int main(int argc, char** argv) {
  
      vector&lt; vector&lt;int&gt; &gt; testMatrixOne(4);
      vector&lt; vector&lt;int&gt; &gt; testMatrixTwo(4);
  
      // Creating a test matrix
      testMatrixOne = {{1,2},{3,4}};
      testMatrixTwo = {{5,6},{7,8}};
  
      // Create Matrix object
      Matrix matrixOne(testMatrixOne);
      Matrix matrixTwo(testMatrixTwo);
  
      // Create Matrix to store difference
      Matrix diff;
      diff = matrixOne - matrixTwo;
      diff.print();
  
  
      return 0;
  }
  </code></pre>
  
  <p>I have simplified my code and hardcoded in two matrices. When running the program, the size() will return a very large integer. I have spent several hours searching online but couldn't find out what's the cause of this. Why is the size() function doing this?</p>