Templates in C++ - Pros and Cons
By SergeyChepurin | 29 Oct 2011
Advantages and drawbacks of usingtemplates in C++ projects
Licence CPOL First Posted 29Oct 2011 Views 3,549 Bookmarked 13 times
4.50 (8 votes)
Introduction
Once upon a time, I decided to collect and organize all the advantages anddrawbacks you may experience when using templates in C++.
Advantages
使你能够定义操作不同类型信息的函数族或是类族。
C++ templates enable you to define a family of functions or classes that canoperate on different types of information.
- Use templates in situations that result in duplication of the same code for multiple types.
For example, you can use function templates to create a set of functions that apply the same algorithm to different data types.
在一些场景可以避免重复代码 - You can also use class templates to develop a set of typesafe classes.
使用class templates开发一组