|
-
Apr 11th, 2001, 09:38 AM
#1
Thread Starter
Lively Member
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.
-
Apr 12th, 2001, 05:43 PM
#2
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|