What happens is that the compiler creates an instance of the function for each type (used, of course,). This way you will have internal functions:
int my_max (const int &t1, const int &t2)
{
static int counter = 0;
counter++;
cout << counter << " ";
return ((t1 > t2) ? t1 : t2);
}
...
double my_max (const double &t1, const double &t2)
{
static int counter = 0;
counter++;
cout << counter << " ";
return ((t1 > t2) ? t1 : t2);
}
...
char my_max (const char &t1, const char &t2)
{
static int counter = 0;
counter++;
cout << counter << " ";
return ((t1 > t2) ? t1 : t2);
}
I think it is clear that each function is independent. They have nothing, except that they are generated by the same template code.
source
share