samedi 30 juillet 2016

universal and uniform initialization: `double` to `int`

Visual Studio 2015 Update 3. C++11\C++14.

For int:

constexpr int ci1 {50};
constexpr int ci2 {500};

char c1 {ci1}; // OK
char c2 {ci2}; // compilation error

I.e. the universal and uniform initialization can check the value in the compilation mode (from int to char). This case was mentioned by Bjarne Stroustrup in his book.

I expected that this is true for case double to int,but it doesn't work for Visual Studio 2015 Update 3:

constexpr double cd {4.0};
int i1 {cd}; // compilation error

Is it correct behaviour (for my second code example) or maybe it is specific for Visual Studio?

Aucun commentaire:

Enregistrer un commentaire