Skip to content

Commit f65d0a7

Browse files
authored
Templates for Functions used in STL
1 parent 8154e18 commit f65d0a7

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

CPP/stl/Function Template.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <iostream>
2+
#include<bits/stdc++.h>
3+
using namespace std;
4+
5+
//general syntax for templates
6+
template <typename T>
7+
8+
//funcation creation with templates
9+
T maxi(T a,T b)
10+
{
11+
if (a>b)
12+
{
13+
return a;
14+
}
15+
else
16+
{
17+
return b;
18+
}
19+
}
20+
21+
int main()
22+
{
23+
cout<<maxi<int>(3,6)<<endl;
24+
cout<<maxi<float>(3.5,6.2)<<endl;
25+
return 0;
26+
}

0 commit comments

Comments
 (0)