Advertisement
Guest User

Untitled

a guest
Sep 16th, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. // In cpp file
  2. // 1)
  3.  
  4. template <class T>
  5. Matrix<T> Matrix<T>::operator[](const int r)
  6. {
  7.     Matrix newMatrix(1,cols);
  8.  
  9.     for (unsigned int k = 0;k<cols;k++)
  10.     {
  11.         newMatrix.matrix[0][k] = matrix[r][k];
  12.     }
  13.  
  14.     return newMatrix;
  15. }
  16.  
  17. // in .h file
  18. // 2)
  19.     friend ostream& operator << (ostream & output, Matrix<T>& o)
  20.     {
  21.         for (unsigned int x = 0;x<o.rows;x++)
  22.         {
  23.             for (unsigned int y = 0;y<o.cols;y++)
  24.             {
  25.                 output << o.matrix[x][y];
  26.  
  27.                 if (y != (o.cols-1))
  28.                 {
  29.                     output << " ";
  30.                 }
  31.             }
  32.  
  33.             output << endl;
  34.         }
  35.  
  36.         return output;
  37.     }
  38.  
  39. // 3)
  40.  Matrix operator[](const int r);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement