example and use of a template

hello

i would like to create a template because i really need it!
so i had focus an example but i haven't find any thing that is simple
so can you give me a simple example juste a simple one how to declare and use a template and specialy how to use it in an example??


think you for help
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
using namespace std;

template<typename T>
class cAdd
{
public:
	//just a function
	T Add(T param1, T param2);

private:


};

template<typename T>
T cAdd<T>::Add(T param1, T param2)
{
	return (param1 + param2);
}


void main()
{
	cAdd<int> Add_i;	//type int
	cout << Add_i.Add(10, 20) << endl;

	cAdd<double> Add_d;		//type double
	cout << Add_d.Add(10.234, 20.546) << endl;

	cAdd<char> Add_c;	//type char
	cout << Add_c.Add('A', 'B') << endl;

	return;

}
thinks!
Topic archived. No new replies allowed.