fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <class T>
  5. const T& max(const T& a1, const T& a2)
  6. {
  7. cout << "genereal template " << a1 << " " << a2 << endl;
  8. return (a1 < a2) ? a2 : a1;
  9. }
  10.  
  11. template <class T>
  12. const T* max(const T* a1, const T* a2)
  13. {
  14. cout << "template for pointers" << endl;
  15. return (a1 < a2) ? a2 : a1;
  16. }
  17.  
  18. template <class T>
  19. const T& max(const T& a1, const T& a2, const T& a3)
  20. {
  21. cout << "general template with three parameters" << endl;
  22. return ::max(::max(a1, a2), ::max(a1, a3));
  23. }
  24.  
  25. int main()
  26. {
  27. int* a = new int(5);
  28. int* b = new int(56);
  29. int* c = new int(2);
  30. int* g = ::max(a, b, c);
  31. cout << *g << endl;
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0s 3228KB
stdin
Standard input is empty
stdout
general template with three parameters
genereal template 0x9f8f008  0x9f8f028
genereal template 0x9f8f008  0x9f8f018
genereal template 0x9f8f018  0x9f8f028
2