decltype
根据表达式的类型自动推导类型
int main(void)
{
decltype(x) c = 21.1; //赋值
decltype((x)) d = c; // 是一个引用
decltype(x) e = c; //
d = 120;
cout << sizeof(int) << endl;
cout << sizeof(c) << " c=" << c << endl; // c的类型按照 x的类型进行显示
cout << sizeof(d) << " d=" << d << endl;
cout << sizeof(e) << " e=" << e << endl;
return 0;
}
template <typename T, typename T2>
auto ADD(T a, T2 b) -> decltype(a+b)
{
return a + b;
}
int main(void)
{
int a = 10;
int b = -5;
double x = 10.1;
double y = -5.1;
cout << ADD(a, x) << endl;
}