54.函数模板默认参数

 1 #include <iostream>
 2 using namespace std;
 3 
 4 //模板可以设置有默认值
 5 template <class T = char*,int n = 10>
 6 void hello(T str)
 7 {
 8     cout << n << endl;
 9     cout << str << endl;
10 }
11 
12 //节约输入参数
13 template <class T1 = int, class T2 = int , class T3 = int>
14 void show(T1 t1 = 1, T2 t2 = 2, T3 t3 = 3)
15 {
16     cout << t1 << t2 << t3 << endl;
17 }
18 
19 
20 void main()
21 {
22     //函数模板调用可以自己推导类型也可以自己赋予类型
23     hello<char *,100>("hello");
24     show<int, int, int>();
25     cin.get();
26 }
原文地址:https://www.cnblogs.com/xiaochi/p/8552902.html