template c++
#include
using namespace std;
// One function works for all data types. This would work
// even for user defined types if operator '>' is overloaded
template
T myMax(T x, T y)
{
return (x > y)? x: y;
}
int main()
{
cout << myMax(3, 7) << endl; // Call myMax for int
cout << myMax(3.0, 7.0) << endl; // call myMax for double
cout << myMax('g', 'e') << endl; // call myMax for char
return 0;
}
cpp template
#include
using namespace std;
int main()
{
return 0;
}
template c++
template function_declaration;
template function_declaration;
//Example:
template
void Swap( Type &x, Type &y)
{
Type Temp = x;
x = y;
y = Temp;
}
template c++
template
myType GetMax (myType a, myType b) {
return (a>b?a:b);
}
c++ template
template //or it´s the same
//T can be int, float, double, etc.
//simple use example:
T sum(T a, T b)
{
return a + b;
}
sum(5.0f, 10f);//sum using float
sum(2,3);//sum using int
c++ template
int x,y;
GetMax (x,y);
|