Function Templates - Example 10-6 - A function template using two types
// File: ex10-6.cpp
#include <iostream>
using namespace std;
template <class X, class Y> void print_em(X a, Y b)
{
cout.setf(ios::right,ios::adjustfield);
cout.width(10);
cout << static_cast<int>(a);
cout.precision(2);
cout.setf(ios::showpoint);
cout.width(10);
cout << static_cast<double>(b) << endl;
return;
}
int main(void)
{
print_em(3,4);
print_em(3,5.7);
print_em(5.11,9);
print_em(static_cast<short>(3),7.777);
print_em(static_cast<long>(5),static_cast<float>(3.456));
print_em('A',5);
print_em(5,'A');
return 0;
}
/***** Output *****
3 4.0
3 5.7
5 9.0
3 7.8
5 3.5
65 5.0
5 65.
*********************/