fork download
  1. #include <iostream>
  2.  
  3. // maximum of two values of any type:
  4. template<typename T>
  5. T max (T a, T b)
  6. {
  7. std::cout << "max<T>() \n";
  8. return b < a ? a : b;
  9. }
  10.  
  11. // maximum of three values of any type:
  12. template<typename T>
  13. T max (T a, T b, T c)
  14. {
  15. return max (max(a,b), c); // uses the template version even for ints
  16. } //because the following declaration comes
  17. // too late:
  18.  
  19. // maximum of two int values:
  20. int max (int a, int b)
  21. {
  22. std::cout << "max(int,int) \n";
  23. return b < a ? a : b;
  24. }
  25.  
  26. int main()
  27. {
  28. ::max(47,11,33); // OOPS: uses max<T>() instead of max(int,int)
  29. }
Success #stdin #stdout 0s 4296KB
stdin
Standard input is empty
stdout
max<T>() 
max<T>()