S
Stefan Ram
#include <iostream>
#include <ostream>
int main()
{ ::std::cout << int( 2.6 )<< '\n';
::std::cout << int{ 2.6 }<< '\n';
::std::cout << ( int )2.6 << '\n';
::std::cout << static_cast< int >( 2.6 )<< '\n'; }
Under which circumstances is which way of the above to
convert a double to an int the best style?
Are there any differences in the semantics above?
Is there yet another way to write the conversion?
PS: Oh yeah: the int{} notation forbids narrowing!
I should have compiled with -pedantic-errors!
So, int{} differs from the rest, it is not a kind of
cast or conversion, rather a compile-time assertion
of the number being not wider than int?
Is the number »2.6« an argument or an operand in
»int{ 2.6 }«? It does not seem to be a function
call. So it is not an argument. But is this an
application of an operator? No. So it also is not
an operand? So, what is it then?
#include <ostream>
int main()
{ ::std::cout << int( 2.6 )<< '\n';
::std::cout << int{ 2.6 }<< '\n';
::std::cout << ( int )2.6 << '\n';
::std::cout << static_cast< int >( 2.6 )<< '\n'; }
Under which circumstances is which way of the above to
convert a double to an int the best style?
Are there any differences in the semantics above?
Is there yet another way to write the conversion?
PS: Oh yeah: the int{} notation forbids narrowing!
I should have compiled with -pedantic-errors!
So, int{} differs from the rest, it is not a kind of
cast or conversion, rather a compile-time assertion
of the number being not wider than int?
Is the number »2.6« an argument or an operand in
»int{ 2.6 }«? It does not seem to be a function
call. So it is not an argument. But is this an
application of an operator? No. So it also is not
an operand? So, what is it then?