Saturday, December 19, 2009

Summary




I l@ve RuBoard


Summary


In this chapter, we looked at a powerful tool for code reuse: C++ templates. The underlying idea is very simple and attractive: If the algorithms should be the same for different types, you should write it only once and later indicate for what actual type you want this algorithm to be used.



This is the ideal, but the practical use of this idea faces a number of difficulties. The syntax of C++ templates is complex. The use of specializations complicates matters even more. Sometimes figuring out which specialization will be called in each case becomes a chore. Sometimes, what works on one machine under one compiler will not work on another machine under a different compiler.



In addition, the use of templates entails space and performance penalty. This is why many C++ programmers try to avoid templates. On the other hand, templates are utilized in the Standard Template Library (STL), and you have to understand the basic principles of using templates to be able to handle the STL library correctly.



It is a powerful tool. Use it with care.







I l@ve RuBoard

No comments: