1显示具体化:
声明:template<class T>
void test(T t); //这个在显示具体化中为一般的模板函数
template<> void test<int> (int a); //【显示具体化函数】
定义: template<class T>
void test(T t){ .....}
template<> void test<int>(int a){ ......}
调用:直接用函数名称即可
如:test(3); //参数为int,调用具体化
test(3.3); //参数不为int, 调用一般模板函数
再看一下实例具体化:
声明:template<class T>
void test(T t);
void test(float f);
定义:template<class T>
void test(T t){......} //【实例具体化函数】
void test(float t){.....} //一般函数,拿来对比
调用:【这点区别很大】
template void test<int>(int t); //要先说明一下类型才能调用实例具体化
test(3); //参数为int,调用实例具体化
test(3.3); //参数不为int, 调用一般函数
从上面可以看出,其实显示具体化就是【在函数声明的时候就已经确定了具体类型要调用的具体函数】,而实例具体化是【在函数调用的时候去确定一个类型,使其调用具体化的函数】
从这两个可以看出,两个实例化就是【为了照顾一些你想特殊处理的类型,让它不按模板进行】,说白了就是搞特殊嘛,呵呵,编程也得有特殊待遇