【发布时间】:2015-05-07 07:36:00
【问题描述】:
在 C++11 中,当我写这篇文章时,x 和 y 的类型是什么?
int main()
{
auto x = true ? 1 : 1.0;
auto y = false ? 1 : 1.0;
std::cout << x << endl;
std::cout << y << endl;
return 0;
}
【问题讨论】:
-
template<class>struct typeof;template struct typeof<std::common_type_t<int,double>>; -
你可以使用typeid(我也认为 boost 有自己的 typeid 之类的东西)
-
是
int和double的常用类型,所以double。
标签: c++ c++11 types auto ternary-operator