c++ - C++11 类型推断如何决定 float 或 double ?

标签 c++ c++11 type-inference

考虑这个类型推断的例子:

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/

相关文章:

c++ - 继承 pod 的大括号初始化

scala - 为什么在没有子类型证据的情况下,这个多函数案例的隐式推导会失败?

c++ - 在使用 Bazel Build 构建项目期间处理/选择接口(interface)的不同实现

c++ - 显式析构函数调用不起作用

c++ - 为什么将指针转换为引用在我的访问器 (getter) 中不起作用?

c++ - 局部变量模板的实例化

c++ - 引用c++临时字符串的内容

C++ 单例实例禁用重新调用

rust - 为什么使用 "Self"作为参数类型会引发生命周期错误?

haskell - 不完整的类型签名