-
i'm not sure about where you can find the information but I'll tell you what i know.
Templates are the same as functions other than they can use different data types every time they are called.
Code:
Template <class T>
t add(T left, T right)
{
return(left + right);
}
this will allow you to add two of any data type.
if you want programs that show you how templates and operators are used you can visit
cs.stmarys.ca/~csc227
this is the webpage for my c++ class.
There are many programs in the lab section that show how to use operators
and templates and they have a lot of comments that may be able to help.
-
Quote:
Originally posted by Optic
Code:
Template <class T>
t add(T left, T right)
{
return(left + right);
}
C++ is Case Sensitive. So this would not work, the data type for the function would have to be upper case. It's not a good idea to use templates for functions that perform arithmatic operations, you could get some screwed up results if the person chooses the datatype as a string or user defined type.