fork download
  1. #include <iostream>
  2. #include <stdint.h>
  3.  
  4. template <typename T>
  5. union test
  6. {
  7. using mytype = T;
  8. friend std::ostream& operator<<(std::ostream& stream, test<T> t)
  9. {
  10. stream << static_cast<mytype>(65);
  11. }
  12. };
  13.  
  14. int main() {
  15. test<int> t;
  16. std::cout << t;
  17. return 0;
  18. }
  19.  
Compilation error #stdin compilation error #stdout 0s 15232KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘std::ostream& operator<<(std::ostream&, test)’:
prog.cpp:10:28: error: ‘mytype’ does not name a type
      stream << static_cast<mytype>(65);
                            ^~~~~~
prog.cpp: In function ‘int main()’:
prog.cpp:15:10: error: non-template type ‘test’ used as a template
  test<int> t;
          ^
stdout
Standard output is empty