I have some old-style casting in some c++ code which I would like to convert to new-style. I had a look to precedence and associativity operators documentation, but I failed to understand it.
( double ) myValueA() / myValueB()
is equivalent to
static_cast<double>( myValueA() ) / myValueB()
or to
static_cast<double>( myValueA() / myValueB() )
I suppose the answer will the same for other numerical operators (*/+-)
In
( double ) myValueA() / myValueB()
( double )
is a c-style cast. If we look at the operator precedence table we will see that it has a higher precedence than the arithmetic operators so
( double ) myValueA() / myValueB()
is the same as
static_cast<double>(myValueA()) / myValueB()
The cast has higher precendence, so it is equivalent to
static_cast<double>(myValueA()) / myValueB()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With