• Source
    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 two int values:
    12. int max(int a, int b)
    13. {
    14. std::cout << "max(int,int) \n";
    15. return b < a ? a : b;
    16. }
    17.  
    18. // maximum of three values of any type:
    19. template<typename T>
    20. T max (T a, T b, T c)
    21. {
    22. return max (max(a,b), c);
    23. }
    24.  
    25. struct S {};
    26.  
    27. S max(S, S)
    28. {
    29. std::cout << "max(S,S)\n";
    30. return {};
    31. }
    32.  
    33.  
    34.  
    35. int main()
    36. {
    37. ::max(47, 11, 33);
    38. ::max(S{}, S{}, S{});
    39. }