考虑这个类型推断的例子:
auto var = 1.0 ;
在 C++11 类型推断下,它的计算结果是 float 还是 double?可以控制这种行为吗?
最佳答案
它将被评估为 double
是的,您可以控制它。
在标准 ISO-14882:2011 中,2.14.4 float 文字,第 1 点:
The type of a floating literal is double unless explicitly specified by a suffix. The suffixes f and F specify float, the suffixes l and L specify long double. If the scaled value is not in the range of representable values for its type, the program is ill-formed.
关于c++ - C++11 类型推断如何决定 float 或 double ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12553359/