#include template class Matrix; template std::ostream& operator<<( std::ostream& ostr, const Matrix& m); template class Matrix { private: int _rank; friend std::ostream& operator<< <> ( std::ostream& ostr, const Matrix& m ); }; template std::ostream& operator<<( std::ostream& ostr, const Matrix& m ) { (void) m._rank; // test friendship return ostr; } void f(const Matrix& m) { std::cout << m; }