fork download
  1. #include <iostream>
  2.  
  3. struct ostream {} cout;
  4. template<typename T> struct A{ T t; };
  5. struct B{};
  6.  
  7. namespace {
  8. template<typename T>
  9. ostream& operator<< (ostream& out, const A<T>&v)
  10. { return out << v.t; }
  11.  
  12. ostream& operator<< (ostream& out, const B&)
  13. { std::cout << "This should not compile" << std::endl; return out; }
  14.  
  15. void foo (const B &b) { std::cout << "hello" << std::endl; }
  16.  
  17. template<typename T>
  18. void foo (const A<T> &a) { foo(a.t); }
  19. }
  20.  
  21. int main(){
  22. A<B> a;
  23. cout << a;
  24. foo(a);
  25. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
This should not compile
hello