This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Template non-member friend

By: a guest on Nov 9th, 2010  |  syntax: C++  |  size: 0.52 KB  |  views: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data