K
krchandu
inline int const& max (int const& a, int const& b)
{
cout << "Normal function called \n";
return a<b?b:a;
}
// maximum of two values of any type
template <typename T>
inline T const& max (T const& a, T const& b)
{
cout << "Template function with 2 param called \n";
return a<b?b:a;
}
int main()
{
::max(7, 42); // calls the nontemplate for two ints
::max<>(7, 42); // calls max<int> (by argument deduction)
}
Here, function call max<>(7, 42); instantiate the max template for int
as if it was declared and implemented individually. But there is a non-
template function with same signature. How can it be possible to have
two functions with same signatures?
{
cout << "Normal function called \n";
return a<b?b:a;
}
// maximum of two values of any type
template <typename T>
inline T const& max (T const& a, T const& b)
{
cout << "Template function with 2 param called \n";
return a<b?b:a;
}
int main()
{
::max(7, 42); // calls the nontemplate for two ints
::max<>(7, 42); // calls max<int> (by argument deduction)
}
Here, function call max<>(7, 42); instantiate the max template for int
as if it was declared and implemented individually. But there is a non-
template function with same signature. How can it be possible to have
two functions with same signatures?