c11 decltype与auto
程序员文章站
2022-07-14 08:07:16
...
#include <iostream>
#include <cstdarg>
#include <vector>
using namespace std;
template<typename T, typename D>
auto Add(T t, D d)->decltype(t+d) //指明返回类型
{
return t + d;
}
int main()
{
int temp = 0;
decltype(temp) te = 10;
cout << te << endl;
cout << Add(12.5, 10) << endl;
vector<int> vec;
for (size_t i = 0; i < 10; i++)
{
vec.push_back(i);
}
for (int i : vec)
{
cout << i << endl;
}
cin.get();
return 0;
}
上一篇: c11 chrono详解
下一篇: C11新特性
推荐阅读