4.auto详解

Posted xiaochi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了4.auto详解相关的知识,希望对你有一定的参考价值。

 1 #include <iostream>
 2 using namespace std;
 3 
 4 template <calss T1,class T2>
 5 auto add(T1 t1, T2 t2)
 6 {
 7     return t1 + t2;
 8 }
 9 
10 //auto自适应数据类型,自动推理
11 void main()
12 {
13     auto num = 10;
14     cout << typeid(num).name() << endl;
15 
16     int a[5] = { 1,3,4,5,6 };
17     
18     for (auto i : a)
19     {
20         cout << i << endl;
21     }
22 
23     cin.get();
24 }

 

以上是关于4.auto详解的主要内容,如果未能解决你的问题,请参考以下文章