hmm ,i just figured out about templates?but i have one question?
should they be used in programming alot or are there certain cases..i dont want to learn something not usefull
hmm ,i just figured out about templates?but i have one question?
should they be used in programming alot or are there certain cases..i dont want to learn something not usefull
They are very useful, especially for general-purpose functions like sorting or searching functions.
[edit] They weren't included in Java originally because it was thought that they were too compilcated, by the latest version of Java has them. They put them in because they were tired of overloading functions for every data type. [/edit]
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
thank you ,im sure ill get the hang of them
They should be used when needed. The type of project you are working on will dictate if that means a lot ot not.
At the very simplest level of usage, templates enable the coding of type independent functions. Whether you need this or not is obviously a matter of what you are doing and your personal preferences. Certainly a template is a much cleaner choice than overloading 4 functions to do the same exact thing.
At a more complex level, templates serve as a way to code classes and functions that are polymorphic across non related types. This is a powerful coding practice known as Generic Programming. Here the coder doesn't have many choices. He may be forced into this model by his project at the expense of, if not doing it, having a much more complex and hard to manage code. As an example, the STL wouldn't have been as popular and as powerful as it is today if it didn't rely on generic programming.
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
You will certainly need to use code that uses templates, but you won't actually write templated code all that often, especially as a relative beginner to the language. As long as you understand how to use them, I would just get a quick overview of writing them and save the deep study until you feel you are advanced in other areas of C++.