As this tutorial explained, this is a Function Template. The general form of a function template definition is shown here :
template <class type> ret-type func-name(parameter list) {
// body of function
}
The min
and max
macros used in these function templates that defined as :
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define max(a,b) (((a) > (b)) ? (a) : (b))
So in these function templates, The minimum and maximum number between a4
and b4
are detected, then returned in C &a4
:
template<class C> void mini(C &a4, C b4)
{
a4 = min(a4, b4);
}
template<class C> void maxi(C &a4, C b4)
{
a4 = max(a4, b4);
}
In this example I defined it with the int
and the float
data-types (class C
in the function template):
int main()
{
int i1 = 1;
int i2 = 2;
float f1 = 12.5;
float f2 = 12.4;
mini<int>(i1, i2);
maxi<float>(f2, f1);
std::cout << i1 << ", " << i2 << ", " << f1 << ", " << f2 << std::endl;
return 0;
}
The result is :
1, 2, 12.5, 12.5
Notice : The min
and mx
macros defined in windows.h file by default.... but these macros are simple and you can define them by yourself instead and not using of windows header file. And I recommend using of std::min
and std::max
that are for c++