可变参数高级模板
1 #include<iostream>
2 #include<cstdarg>
3
4 void showall(){};//预留一个
5
6
7 template <typename T>
8 void show(T t, ...)
9 {
10 std::cout << t << std::endl;;
11 }
12
13 template <typename T,typename...Args>
14
15 void showall(T t, Args...args)
16 {
17
18 std::cout << t << std::endl;
19
20 showall( args...);
21
22 }
23
24 void main()
25 {
26 int num1 = 10, num2 = 9, num3 = 11;
27 double db1 = 10.8, db2 = 10.9;
28 char str[40] = "zhangsan";
29 char ch = 'A';
30 show(num1);
31 showall(num2,num3);
32 showall(num2, num3,num1,str,ch);
33
34 std::cin.get();
35 }
长风破浪会有时,直挂云帆济沧海
posted on 2015-05-31 16:04 Dragon-wuxl 阅读(115) 评论(0) 收藏 举报
浙公网安备 33010602011771号