# Include <iostream>
Using Namespace STD;
// Returns the maximum value of two int values.
Inline Int Const & MAX ( Int Const &, Int Const & B)
{
Return A <B? B:;
}
// Evaluate the iterator of two values of any type
Template <typename T>
Inline t Const & MAX (T Const & A, T Const & B)
{
Return A <B? B:;
}
Int Main ()
{
: Max ( 7.0 , 42.0 );// Call max <double> (using real arguments)
: Max ( ' A ' , ' B ' ); // Call max <char> (using real arguments)
: Max ( 7 , 42 ); // Call an int-heavy non-Template Function
: Max <> ( 7 , 42 ); // Call max <int> (using real arguments)
: Max < Double > ( 7 , 42 ); // Call max <double> (using real arguments)
: Max ( ' A ' , 42.7 ); // Call an int-heavy non-Template Function
Return 0 ;
}
A non-template function can coexist with a function template with the same name, and the function template can also be instantiated as this non-template function. For non-template functions and function templates with the same name, if other conditions are the same, during the call, the overload parsing process usually calls non-template functions.
Max <> () tells the compiler that only the template can match the call, and all the template parameters should be deduced according to the call real parameters.
Max ('A', 42.7) calls int-heavy non-template functions: the template does not allow automatic type conversion, but normal functions can perform automatic type conversion.