C++ function template instance

参考:http://www.learncpp.com/cpp-tutorial/132-function-template-instances/

 1 #include <stdio.h>
 2 
 3 template<typename T>
 4 auto foo(T arg){
 5     return ++arg;
 6 }
 7 
 8 int main()
 9 {
10     auto p = (int(*)(int)) &foo;
11 
12     printf("%d\n",p(5));
13 }

这种模板实例化的方法,我是第一次见。把模板取地址,强制转换为函数指针。

posted @ 2018-04-10 13:59  thomas76  阅读(122)  评论(0编辑  收藏  举报