Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. Matrix& operator=(const Matrix& matr);//Оператор присваивания
  2. Matrix(const Matrix &matr); //Конструктор копирования
  3.  
  4. Matrix::Matrix(const Matrix &matr){//Конструктор копирования
  5.  
  6. m_rows = matr.m_rows;
  7. m_cols = matr.m_cols;
  8.  
  9. m_matrix = new int*[m_rows];
  10. for (int i = 0; i < m_rows; i++)
  11. m_matrix[i] = new int[m_cols];
  12.  
  13. for (int i = 0; i < m_rows; i++)
  14. for (int j = 0; j < m_cols; j++)
  15. m_matrix[i][j] = matr.m_matrix[i][j];
  16.  
  17. }
  18.  
  19. Matrix& Matrix::operator = (const Matrix& matr){//Оператор присваивания
  20.  
  21. if (&matr == this){
  22. }else{
  23.  
  24. m_rows = matr.m_rows;
  25. m_cols = matr.m_cols;
  26.  
  27. m_matrix = new int*[m_rows];
  28. for (int i = 0; i < m_rows; i++)
  29. m_matrix[i] = new int[m_cols];
  30.  
  31. for (int i = 0; i < m_rows; i++)
  32. for (int j = 0; j < m_cols; j++)
  33. m_matrix[i][j] = matr.m_matrix[i][j];
  34.  
  35. }
  36. return *this;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement