Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 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.         this->ptr = result.ptr;
  27.          for (int i = 0; i < l; i++)
  28.             for (int j = 0; j < c; j++)
  29.                 {
  30.                     cout << this->ptr[i][j] << " ";
  31.                 }
  32.         return *this;
  33.     }
  34.     else
  35.         return m1;
  36.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement