954,168 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

The difference between functions and templates?

What is the difference between function template & template function?

Thanks.

Nasimov
Newbie Poster
2 posts since Dec 2003
Reputation Points: 10
Solved Threads: 0
 

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 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.

cscgal
The Queen of DaniWeb
Administrator
19,421 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 229
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You