943,740 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 4374
  • C++ RSS
Dec 4th, 2003
0

The difference between functions and templates?

Expand Post »
What is the difference between function template & template function?

Thanks.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Nasimov is offline Offline
2 posts
since Dec 2003
Dec 4th, 2003
0

Re: The difference?

Well, you could have a regular ol' function named template. i.e. int template(char letter) or void template() or any other combination you could have for a function. There's also a C++ thingie called templates, where you would do something such as Template<T> or something along those lines. (I've never learned/used them personally). However, what they allow you to do is abstract data types out from your code. For example, take the algorithm for a linked list. You can add data to the list, remove data, search the list, sort the list, etc. However, just to add data to the end of the list, for example, it doesn't matter what data type the list is. Templates allow you to avoid redoing multiple classes and functions for an integer linked list, a character linked list, a double linked list, etc. Rather, you can abstract out this data by creating a linked list of type T. This way you can reuse that part of your code.
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is offline Offline
13,645 posts
since Feb 2002

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: compiling problems
Next Thread in C++ Forum Timeline: Completely new to C++ and have question about using char





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC