fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <class T>
  5. class test {
  6. private:
  7. T a;
  8. public:
  9. test(const T &b) : a(b) {}
  10. friend ostream & operator << (ostream &, const test &);
  11. };
  12.  
  13. ostream & operator << (ostream &out, const test &t) {
  14. return out<<t.a;
  15. }
  16.  
  17. int main() {
  18. test <double> T(3.141);
  19. cout<<T;
  20. return 0;
  21. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:10:55: warning: friend declaration 'std::ostream& operator<<(std::ostream&, const test<T>&)' declares a non-template function [-Wnon-template-friend]
  friend ostream & operator << (ostream &, const test &);
                                                       ^
prog.cpp:10:55: note: (if this is not what you intended, make sure the function template has already been declared and add <> after the function name here) 
prog.cpp:13:44: error: invalid use of template-name 'test' without an argument list
 ostream & operator << (ostream &out, const test &t) {
                                            ^
prog.cpp: In function 'std::ostream& operator<<(std::ostream&, const int&)':
prog.cpp:14:16: error: request for member 'a' in 't', which is of non-class type 'const int'
  return out<<t.a;
                ^
stdout
Standard output is empty