码迷,mamicode.com
首页 > 编程语言 > 详细

C++11 可变参数模板

时间:2015-08-20 12:40:32      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:

 1 #include<iostream>
 2 using namespace std;
 3 
 4 //function to end the recursion and print the last element
 5 //function must declare before the variadic version of print is defined
 6 template<typename T>
 7 ostream& print(ostream& os,const T& t)
 8 {
 9     os << t;
10 }
11 
12 //this version of print willed  be called for all but the last element
13 //int the pack
14 template<typename T,typename...Args>
15 ostream &print(ostream& os,const T& t,const Args&...args)
16 {
17     os<< t << ",";
18     return print(os,args...);
19 }
20 
21 int main()
22 {
23     print(cout,1,2,3,\n);
24     print(cout,4,"hello,world",\n);
25     return 0;
26 }

 

C++11 可变参数模板

标签:

原文地址:http://www.cnblogs.com/wxquare/p/4744546.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!