fork download
  1. #include <iostream>
  2. #include <typeinfo>
  3. using namespace std;
  4.  
  5. template <typename T>
  6. class someContainer
  7. {
  8. private:
  9. T val1;
  10. T val2;
  11. public:
  12. someContainer(const T& in1, const T& in2)
  13. :val1(in1), val2(in2) {}
  14.  
  15. template <typename Ret = bool ,typename Ty = T>
  16. void sort(Ret (*_comp)(const Ty&, const Ty&))
  17. {
  18. cout << "Comp is of type: " << typeid(_comp).name() << endl;
  19. cout << _comp(val1, val2) << endl;
  20. return;
  21. }
  22. };
  23.  
  24. template <typename Ret, typename R>
  25. Ret compare(const R& a, const R& b)
  26. {
  27. return a>b;
  28. }
  29.  
  30. int main()
  31. {
  32. someContainer<int> myCont(7,6);
  33. myCont.sort(compare);
  34.  
  35. cin.ignore();
  36. return 0;
  37. }
Success #stdin #stdout 0s 2856KB
stdin
Standard input is empty
stdout
Comp is of type: PFbRKiS0_E
1