10

Consider this example of type inference:

auto var = 1.0 ;

Does this evaluate to a float or double under C++11 type inference?, can this behaviour be controlled?

4

1 に答える 1

15

It will be evaluated as a double and yes, you can control it.

In the standard ISO-14882:2011, 2.14.4 Floating literals, point 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.

于 2012-09-23T15:00:30.383 に答える