Guest User

Untitled

a guest
Oct 1st, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. const size_t SIZE = 4;
  2.  
  3. template<typename T>
  4. class Matrix
  5. {
  6. private:
  7. T arr[SIZE][SIZE];
  8. friend ostream& operator << (ostream &, const Matrix<T> &);
  9. friend istream& operator >> (istream &, Matrix<T> &);
  10. void initialize();// функция которая заполняет матрицу как единичную
  11.  
  12. public:
  13. Matrix();
  14. Matrix(const Matrix<T>&);
  15. const Matrix& operator=(const Matrix<T>&);
  16. const Matrix& operator*(const Matrix<T>&);
  17. void operator*=(const Matrix<T> &);
  18. T* operator[](int row);
  19. };
  20.  
  21. template< typename T>
  22. ostream & operator<<(ostream & os, const Matrix<T> & rhs)
  23. {
  24. for (int i(0); i < SIZE; ++i)
  25. {
  26. for (int j(0); j < SIZE; ++j)
  27. {
  28. os << rhs.arr[i][j] << ' ';
  29. }
  30. os << endl;
  31. }
  32. return os;
  33. }
  34.  
  35. template< typename T>
  36. istream & operator>>(istream& is, Matrix<T> & rhs)
  37. {
  38. for (int i(0); i < SIZE; ++i)
  39. {
  40. for (int j(0); j < SIZE; ++j)
  41. {
  42. is >> rhs.arr[i][j];
  43. }
  44. }
  45. return is;
  46. }
  47.  
  48. friend ostream& operator << (ostream &, const Matrix<T> &);
  49. friend istream& operator >> (istream &, Matrix<T> &);
  50.  
  51. prog.cpp:13:64: warning: friend declaration 'std::ostream& operator<<(std::ostream&, const Matrix<T>&)' declares a non-template function [-Wnon-template-friend]
  52. friend ostream& operator << (ostream &, const Matrix<T> &);
  53. ^
  54. prog.cpp:13:64: note: (if this is not what you intended, make sure the function template has already been declared and add <> after the function name here)
  55.  
  56. template <typename T1> friend ostream& operator << (ostream &, const Matrix<T1> &);
  57. template <typename T1> friend istream& operator >> (istream &, Matrix<T1> &);
  58.  
  59. friend ostream& operator << (ostream &, const Matrix<T> &);
  60. friend istream& operator >> (istream &, Matrix<T> &);
  61.  
  62. friend ostream& operator << (ostream &, const Matrix<int> &);
  63. friend istream& operator >> (istream &, Matrix<int> &);
  64.  
  65. template< typename T>
  66. std::ostream & operator<<(std::ostream & os, const Matrix<T> & rhs)
  67. {
  68. ...
  69. }
  70.  
  71. friend ostream& operator << (ostream &, const Matrix<int> &);
  72.  
  73. std::ostream & operator<<(std::ostream & os, const Matrix<int> & rhs)
  74. {
  75. ...
  76. }
  77.  
  78. template< typename T>
  79. std::ostream& operator<<(std::ostream & os, const Matrix<T> & rhs)
  80. {
  81. ...
  82. }
  83.  
  84. friend ostream& operator <<<T>(ostream & os, const Matrix & rhs);
  85. friend istream& operator >><T>(istream &, Matrix &);
  86.  
  87. template<typename T>
  88. class Matrix;
  89.  
  90. template< typename T>
  91. std::ostream& operator<<(std::ostream & os, const Matrix<T> & rhs)
  92. {
  93. ...
  94. }
  95.  
  96. template< typename T>
  97. std::istream & operator>>(std::istream& is, Matrix<T> & rhs)
  98. {
  99. ...
  100. }
  101.  
  102.  
  103. template<typename T>
  104. class Matrix
  105. {
  106. private:
  107. T arr[SIZE][SIZE];
  108. friend ostream& operator <<<T>(ostream &, const Matrix &);
  109. friend istream& operator >><T>(istream &, Matrix &);
  110. ...
  111. };
  112.  
  113. friend ostream& ::operator << (ostream &, const Matrix<T> &);
  114. friend istream& ::operator >> (istream &, Matrix<T> &);
  115.  
  116. template<typename T>
  117. class Matrix;
  118.  
  119. template<typename T>
  120. ostream & operator<< (ostream &, const Matrix<T> &);
  121.  
  122. template<typename T>
  123. istream& operator >> (istream &, Matrix<T> &);
  124.  
  125. template<typename T>
  126. class Matrix
  127. {
  128. private:
  129. T arr[SIZE][SIZE];
  130. // объявляем friend'ом конкретную специализацию
  131. friend ostream& operator << <> (ostream &, const Matrix &); // обратите внимание на <>
  132. friend istream& operator >> <> (istream &, Matrix &);
  133.  
  134. ...
Add Comment
Please, Sign In to add comment