参考: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 }

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

相关文章:

  • 2021-09-09
  • 2022-02-17
  • 2022-01-04
  • 2021-09-11
  • 2021-12-17
  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-28
  • 2022-02-04
  • 2022-01-10
  • 2021-10-13
  • 2021-08-09
相关资源
相似解决方案