1. Developing generic function (设计泛型函数)
1.1. Steps (步骤)
(1) To start with non-generic function (先设计/编写一个非泛型函数)
(2) To debug and test it (调试/测试该函数)
(3) To convert it to a generic function (将上述非泛型函数转换为泛型函数)
1.2. How to transform(如何泛型化)
(1) What DATA does the function process? (函数处理哪些数据)
(2) What are the TYPEs of the DATA?(数据的类型是什么)
(3) Transform the TYPEs to TYPE Parameters
2. 示例——Generic Sort Function (泛型排序函数)
2.1. 非泛型函数原型
void selectionSort(double list[] , const int size);
2.2. 泛型函数原型
将double转成T:
template <typename T>
void selectionSort(T list[] , const int size);
注意:模板类的声明和实现不能分离,即都在.h文件中。
标签:Function,function,relevant,型函数,Make,pc,blog,How,非泛 From: https://www.cnblogs.com/spacerunnerZ/p/16960561.html