Created
September 22, 2013 11:23
-
-
Save praveendhinwa/6659027 to your computer and use it in GitHub Desktop.
function template in C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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