title: Matrices Math Issues
body: <pre><code>#include "matrixType.h"
  #include&lt;iostream&gt;
  using namespace std;
  //Default Constructor to Intialize private members of class
  matrixType::matrixType() {
  
      this-&gt;rowSize = 0;
      this-&gt;colSize = 0;
      this-&gt;matrix=0;
  
  }
  //Parameterized Constructor  which performs deep copy of class member variables
  //Purpose:- To Store the input into the object of class
  //Pre-condition :- Class object is initialized to zero by the default constructor
  //Post-condition:- Object is initialized with the parameters
  matrixType::matrixType(int rowSize1, int colSize1) {
      cout&lt;&lt;"In Parameterized Constructor";
      this-&gt;rowSize = rowSize1;
      this-&gt;colSize = colSize1;
      matrix=new int*[rowSize];
      for(int i = 0 ; i &lt; rowSize ; i++ )
          matrix[i] = new int [colSize];
  }
  //Copy constructor  which performs deep copy of class member variables
  //Purpose:- To run before any operations on matrices
  //Pre-condition :- Resultant matrix is zero
  //Post-condition:- We get the resultant Matrix
  matrixType::matrixType(const matrixType &amp;matrix2) {
      cout&lt;&lt;"In copy Constructor";
      rowSize = matrix2.rowSize;
      colSize = matrix2.colSize;
      matrix = matrix2.matrix;
  }
  //Overload outStream &lt;&lt; operator
  //Purpose:- To show output on screen
  ostream&amp; operator&lt;&lt;(ostream&amp;osobj, const matrixType &amp;mat)
  {
      cout &lt;&lt; "matrix is::" &lt;&lt; endl;
      for (int i = 0; i &lt; mat.rowSize; i++)
      {
          for (int j = 0; j &lt; mat.colSize; j++)
          {
              osobj  &lt;&lt; mat.matrix[i][j];
  
          }
          cout &lt;&lt; endl;
  
      }
      return osobj;
  }
  //Overload instream operator
  //Purpose:- To take the input from user
  
  istream&amp; operator&gt;&gt;(istream&amp;isobj, const matrixType &amp;matin)
  {
      for (int i = 0; i &lt; matin.rowSize; i++)
      {
          for (int j = 0; j &lt; matin.colSize; j++)
          {
              isobj &gt;&gt; matin.matrix[i][j];
          }
  
      }
      return isobj;
  }
  
  // member function setMatrix() to read matrix elements from console and initialize
  //Purpose:- To read the values of matrices and set them inobject
  void matrixType::setMatrix() {
      int c, d;
  
      cout &lt;&lt; "\nEnter the elements of matrix\n";
  
      for (c = 0; c &lt; rowSize; c++)
          for (d = 0; d &lt; colSize; d++) {
              cin&gt;&gt;this-&gt;matrix[c][d];
          }
      cout &lt;&lt; "\n\nMatrix :\n\n";
      for (c = 0; c &lt; rowSize; c++) {
          for (d = 0; d &lt; colSize; d++) {
              cout &lt;&lt;"\t"&lt;&lt;this-&gt;matrix[c][d];
          }
          cout &lt;&lt;"\n\n";
      }
  }
  //Equal member function to compare the row and column size of matrices for addition and subtraction
  bool matrixType::equal(matrixType &amp;h){
      if (this-&gt;rowSize==h.rowSize &amp;&amp; this-&gt;colSize==h.colSize)
  
          return true;
      else
          return false;
  }
  //Equate member function to compare the row and column size of matrices for Multiplication
  bool matrixType::equate(matrixType &amp;h){
      if (this-&gt;colSize==h.rowSize)
  
          return true;
      else
          return false;
  }
  //Overloading Assignment Operator
  //Purpose:- To perform assigning operations between the objects of class
  void matrixType:: operator=(const matrixType &amp;matrix2) const
  {
      cout &lt;&lt;"Assign";
  
      for (int i= 0;i &lt;matrix2.rowSize; i++)
      {
          for (int j = 0;j&lt; matrix2.colSize;j++)
          {
              matrix2.matrix[i][j]=matrix[i][j];
          }
      }
  
  }
  //Overloading Addition Operator
  //Purpose:- To perform addition of two objects
  //Pre-condition :- Two class objects of matrixType
  //Post-condition:- Output Object that is the sum of two objects
  matrixType matrixType:: operator+(const matrixType &amp;matrix2) const
  {
      cout &lt;&lt;"Add";
      matrixType matrixSum(rowSize,colSize);
      for (int i= 0;i &lt;matrix2.rowSize; i++)
      {
          for (int j = 0;j&lt; matrix2.colSize;j++)
          {
              matrixSum.matrix[i][j] = matrix[i][j] + matrix2.matrix[i][j];
          }
      }
      cout &lt;&lt; "\n\nMatrix :\n\n";
      for (int c = 0; c &lt; rowSize; c++) {
          for (int d = 0; d &lt; colSize; d++) {
              cout &lt;&lt;"\t"&lt;&lt;matrixSum.matrix[c][d];
          }
          cout &lt;&lt;"\n\n";
      }
      return matrixSum;
  }
  //Overloading subtraction operator
  //Purpose:- To perform subtraction of two objects
  //Pre-condition :- Two class objects of matrixType
  //Post-condition:- Output Object that is the subtraction of two objects
  matrixType matrixType:: operator-(const matrixType &amp;matrix2) const
  {
      cout &lt;&lt;"Subtract";
      matrixType matrixSum(rowSize,colSize);
      for (int i= 0;i &lt;matrix2.rowSize; i++)
      {
          for (int j = 0;j&lt; matrix2.colSize;j++)
          {
              matrixSum.matrix[i][j] = matrix[i][j] - matrix2.matrix[i][j];
          }
      }
      cout &lt;&lt; "\n\nMatrix :\n\n";
      for (int c = 0; c &lt; rowSize; c++) {
          for (int d = 0; d &lt; colSize; d++) {
              cout &lt;&lt;"\t"&lt;&lt;matrixSum.matrix[c][d];
          }
          cout &lt;&lt;"\n\n";
      }
      return matrixSum;
  }
  //Overloading Multiplication Operator
  //Purpose:- To perform multiplication of two objects
  //Pre-condition :- Two class objects of matrixType
  //Post-condition:- Output Object that is the multiplication of two input objects
  matrixType matrixType:: operator*(const matrixType &amp;matrix2) const
  {
      cout &lt;&lt;"Multiplication";
      matrixType matrixM(rowSize,colSize);
      for (int i= 0;i &lt;this-&gt;rowSize; i++)
      {
          for (int k = 0;k&lt; matrix2.colSize;k++)
          {
              matrixM.matrix[i][k]=0;
              for (int j=0;j&lt;matrix2.rowSize;j++){
                  matrixM.matrix[i][k] = matrix[i][j] * matrix2.matrix[j][k];
              }
          }
      }
      cout &lt;&lt; "\n\nMatrix :\n\n";
      for (int c = 0; c &lt; rowSize; c++) {
          for (int d = 0; d &lt; colSize; d++) {
              cout &lt;&lt;"\t"&lt;&lt;matrixM.matrix[c][d];
          }
          cout &lt;&lt;"\n\n";
      }
      return matrixM;
  }
  //destructor which properly removes any resources and deallocates memory
  //Purpose:- To empty the memory used , to make it avaible again
  //Pre-condition:- Objects are present in memory
  //Post-condition:- Memory is empty after removing resources
  matrixType::~matrixType(){
      for (int i = 0; i &lt; rowSize; i++)
          delete[] matrix[i];
          delete[] matrix;
  }
  </code></pre>
  
  <p>I'm having trouble getting this to work correctly. My problem is i'm getting an access read violation at </p>
  
  <pre><code>        matrix2.matrix[i][j] = matrix[i][j];
  </code></pre>
  
  <p>Can't seem to solve it. Any help would be greatly appreciated. I'm pretty sure my pointers are off somewhere. And now im just adding more information because it's making me.</p>