1// function template
2#include <iostream>
3using namespace std;
4
5template <class T>
6T GetMax (T a, T b) {
7 T result;
8 result = (a>b)? a : b;
9 return (result);
10}
11
12int main () {
13 int i=5, j=6, k;
14 long l=10, m=5, n;
15 k=GetMax<int>(i,j);
16 n=GetMax<long>(l,m);
17 cout << k << endl;
18 cout << n << endl;
19 return 0;
20}
1// template specialization
2#include <iostream>
3using namespace std;
4
5// class template:
6template <class T>
7class mycontainer {
8 T element;
9 public:
10 mycontainer (T arg) {element=arg;}
11 T increase () {return ++element;}
12};
13
14// class template specialization:
15template <>
16class mycontainer <char> {
17 char element;
18 public:
19 mycontainer (char arg) {element=arg;}
20 char uppercase ()
21 {
22 if ((element>='a')&&(element<='z'))
23 element+='A'-'a';
24 return element;
25 }
26};
27
28int main () {
29 mycontainer<int> myint (7);
30 mycontainer<char> mychar ('j');
31 cout << myint.increase() << endl;
32 cout << mychar.uppercase() << endl;
33 return 0;
34}