fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <functional>
  4.  
  5. using namespace std;
  6.  
  7. void x(ostream &os) {
  8. os << "x()" << std::endl;
  9. }
  10.  
  11. template <class T>
  12. void y(void (*f)(ostream &), T &os) {
  13. std::cout << "y(): ";
  14. (*f)(os);
  15. }
  16.  
  17. template <class T>
  18. void z(void (*f)(ostream &), T os) {
  19. std::cout << "z(): ";
  20. (*f)(os);
  21. }
  22.  
  23. int main() {
  24. x(cout);
  25. y(x, cout);
  26. //z(x, cout); /* No Good !! because "basic_ostream(const basic_ostream&) = delete;" */
  27. z(x, ref(cout)); /* OK. */
  28. return 0;
  29. }
  30. /* end */
  31.  
Success #stdin #stdout 0s 4396KB
stdin
Standard input is empty
stdout
x()
y(): x()
z(): x()