Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. Matrix operator = (Matrix m1)
  2.         {
  3.             int c, l;
  4.             c = m1.getCols();
  5.             l = m1.getRows();
  6.             cout << l << " " << c;
  7.             //this->n_rows = m1.getRows();
  8.            // cout << "yau";
  9.             //this->n_cols = m1.getCols();
  10.             Matrix result(l, c);
  11.  
  12.     if (this->ptr != m1.ptr)
  13.     {
  14.         for (int i = 0; i < l; i++)
  15.             for (int j = 0; j < c; j++)
  16.                 {
  17.                     result.ptr[i][j] = m1.ptr[i][j];
  18.                     //cout << result.ptr[i][j];
  19.                 }
  20.  
  21.         for (int i = 0; i < this->n_rows; i++)
  22.             delete (this->ptr[i]);
  23.         delete (this->ptr);
  24.         this->n_rows = l;
  25.         this->n_cols = c;
  26.         ptr = new int* [this->n_rows];
  27.             for(int counter = 0; counter < n_rows; counter++)
  28.                 ptr[counter] = new int [this->n_cols];
  29.        // this->ptr = result.ptr;
  30.         for(int i = 0; i < this->getRows(); i++)
  31.             for(int j = 0; j < this->getCols(); j++)
  32.                 this->ptr[i][j] = result.ptr[i][j];
  33.          for (int i = 0; i < l; i++)
  34.             for (int j = 0; j < c; j++)
  35.                 {
  36.                     cout << this->ptr[i][j] << " ";
  37.                 }
  38.         return *this;
  39.     }
  40.     else
  41.         return m1;
  42.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement