Templates look like this:
cpp
template <class T>
T templated_function (T varA, T varB ) {
//CODE
}
To call a template (Example):
cpp
#include <iostream>
using namespace std;
template <class T> //you can replace "T" with what you like...
T add (T a, T B ) { //The reason we need a template here is because you
T returnVal=a+b; //can add ints and floats, and its much easier to use a
return (T); //than making a int add and a float add function, since
} //adding floats is a float and adding ints is an int, so you
//need different return types
int main() {
int a=1;
int b=2;
float x=1.2;
float y=3.4;
cout << add <int> (a,b ) << endl;
cout << add <float> (x,y) << endl;
cin.get();
return 0;
}
for more, go to:
http://www.cplusplus.com/doc/tutorial/templates.htmlhope this helps
This post has been edited by polymath: 9 Jul, 2008 - 08:53 AM