标签:
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 }
标签:
原文地址:http://www.cnblogs.com/wxquare/p/4744546.html