12.模板别名以及auto定义返回值

 1 #include <iostream>
 2 #include <array>
 3 using namespace std;
 4 
 5 //定义返回值类型
 6 template<class T1,class T2>
 7 auto add(T1 t1, T2 t2)->decltype(t1 + t2)
 8 {
 9     return t1 + t2; 
10 }
11 
12 //模板别名,用别名优化模板的名称,只能放在类,命名空间,全局,不能放在函数内部
13 template <class T,int n>using t = array<T, n>;
14 
15 
16 void main()
17 {
18     cout << add(1, 3) << endl;
19     t<int,10> t1;
20     for (auto &i : t1)
21     {
22         i = 1;
23     }
24     for (auto &i : t1)
25     {
26         cout << i << endl;
27     }
28     cin.get();
29 }
原文地址:https://www.cnblogs.com/xiaochi/p/8544013.html