//============================================================== // Templates - Wzorce;
// function template (1) //
// ver data temat autor // 100 2010/11/14 Pierwszy projekt J.Malinowski // 101 2015/10/03 Cleanup JM // 102 2019/12/16 Cleanup JM //============================================================== #include <conio.h> #include <iostream> using namespace std; //---template <class T> T GetMax (T a, T b) { return (a>b)? a : b; // T result = (a>b)? a : b; // return (result); } //============================================================== int main(int argc, char* argv[])
{ int i=5, j=6, k; long l=10, m=5, n; double x=3.3, y=5.5, z; char ch1='a', ch2='z'; char ch3=27;
// function_name <type> (parameters); k = GetMax<int>(i,j); cout << k << endl; n = GetMax<long>(l,m); cout << n << endl; z = GetMax<double>(x,y); cout << z << endl; char ch = GetMax<char>(ch1,ch2); cout << ch << endl; ch = GetMax<char>(ch1,ch3); cout << ch << endl; getch(); return 0; } //==============================================================