fork download
  1. #include <iostream>
  2.  
  3. // prints something;
  4. // the template doesn't add anything
  5. template <typename T>
  6. struct Printer
  7. {
  8. void print()
  9. {
  10. std::cout << "Printer::print" << std::endl;
  11. }
  12. };
  13.  
  14. // this is an actual template
  15. // calls the method indicated by the second template argument
  16. // belonging to the class indicated by the first template argument
  17. template < typename U, void(U::*func)()>
  18. struct Caller
  19. {
  20. void call(U obj)
  21. {
  22. (obj.*func)();
  23. }
  24. };
  25.  
  26. // just a wrapper
  27. template<typename V>
  28. struct Wrapper
  29. {
  30. void call_caller_on_printer()
  31. {
  32. Printer<int> a_printer;
  33. Caller<Printer<int>, &Printer<int>::print> caller;
  34. caller.call(a_printer);
  35. }
  36. };
  37.  
  38. int main()
  39. {
  40. Wrapper<int> the_wrapper;
  41. the_wrapper.call_caller_on_printer();
  42.  
  43. return 0;
  44. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/home/PZEAzK/cclBzO5M.o: In function `main':
prog.cpp:(.text+0x15): undefined reference to `Printer<int>::print()'
collect2: ld returned 1 exit status
stdout

Standard output is empty