Declaring Function Templates - C++ Function Templates ...
Declaring Function Templates - C++ Function Templates Overloading:
Function template declarations usually include a keyword typename or class, to specify that the parameters are going to be of generic type. The following code snippets include declarations for two different overloaded min functions, with the ability to handle 2 and 3 parameters each.
#include
template
T& min(T &tParam1, T &tParam2)
{
if(tParam1 < tParam2)
return tParam1;
else
return tParam2;
}
template
T& min(T &tParam1, T &tParam2, T &tParam3)
{
if(min(tParam1, tParam2) < tParam3)
return min(tParam1, tParam2) ;
else
return tParam3;
}
Calling Function Templates - C++ Function Templates Overloading:
Now we can call min function with 2 or 3 parameters. The following are some of the ways of calling the function templates declared above.
int l_intValue;
l_intValue = min(9,6); //calls min(int,int)
cout ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.