fork(2) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <class T, typename comp>
  5. struct klasa {
  6. comp komparator;
  7. klasa(const T &a, const T &b, comp C = greater<T>()) : komparator(C)
  8. {
  9. cout << C(a, b) << endl;
  10. }
  11. };
  12.  
  13. struct MyCompare
  14. {
  15. bool operator()(const int& a, const int& b) { return true; }
  16. };
  17.  
  18. bool fPtr(const int& a, const int& b) { return false; }
  19.  
  20. int main()
  21. {
  22. klasa<int, greater<int>> a(1, 2);
  23. klasa<int, MyCompare> b(5, 2, MyCompare());
  24.  
  25. auto lessThan = [](const int& a, const int& b) { return a < b; };
  26. klasa<int, decltype(lessThan)> c(1, 5, lessThan);
  27.  
  28. klasa<int, decltype(fPtr)> d(0, 0, fPtr);
  29.  
  30. return 0;
  31. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of ‘struct klasa<int, bool(const int&, const int&)>’:
prog.cpp:28:33:   required from here
prog.cpp:6:7: error: field ‘klasa<int, bool(const int&, const int&)>::komparator’ invalidly declared function type
  comp komparator;
       ^
stdout
Standard output is empty