help in teaching templates in c++
hello it's rizwan from bhavnagar studying in tybca . i want to learn how to create templates in c++ . please help me out by giving a small example.
# 2 Re: help in teaching templates in c++
Here is a thread ( http://www.dev-archive.com/forum/showthread.php?t=401762) discussing books for beginners. I would recommend you get one and use the forum to discuss things you don't understand.
# 3 Re: help in teaching templates in c++
Search the sticky, there is template work examples there.
Here is a very quick example:
template <typename T>
T func(T number)
{
T templateItem;
templateItem = number + 10;
return templateItem;
}
int main()
{
int i1 = 5;
double d1 = 5.0;
int i2 = func(i1); // i2 becomes 15 using T as an int
double d2 = func(d1); // d2 becomes 15.0 using T as a double
}