Advertisement
Guest User

Template non-member friend

a guest
Nov 9th, 2010
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. template <typename T> class Matrix;
  4. template <typename T> std::ostream& operator<<(
  5.     std::ostream& ostr, const Matrix<T>& m);
  6.  
  7. template <typename T>
  8. class Matrix {
  9. private:
  10.     int _rank;
  11.     friend std::ostream& operator<< <> (
  12.       std::ostream& ostr, const Matrix& m );
  13. };
  14.  
  15. template <typename T> std::ostream& operator<<(
  16.     std::ostream& ostr, const Matrix<T>& m )
  17. {
  18.     (void) m._rank; // test friendship
  19.     return ostr;
  20. }
  21.  
  22. void f(const Matrix<int>& m)
  23. {
  24.     std::cout << m;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement