Skip to content

Instantly share code, notes, and snippets.

@praveendhinwa
Created September 22, 2013 11:23
Show Gist options
  • Select an option

  • Save praveendhinwa/6659027 to your computer and use it in GitHub Desktop.

Select an option

Save praveendhinwa/6659027 to your computer and use it in GitHub Desktop.
function template in C++
#include <bits/stdc++.h>
using namespace std;
template <class T>
T Max (T a, T b)
{
T res = a > b ? a : b;
return res;
}
int main()
{
cout << Max <int> (3, 4) << endl; // 4
cout << Max <double> (3.5, 4.6) << endl; // 4.6
cout << Max <string> ("abc", "bcd") << endl; // bcd
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment