首页 > 编程语言 > 详细

C++ function template instance

时间:2018-04-10 14:24:46      阅读:179      评论:0      收藏:0      [点我收藏+]

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

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

C++ function template instance

原文:https://www.cnblogs.com/thomas76/p/8778475.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!