In the Deitel book it tells me to cast as follows:
static_cast< double >( operand )
Yet in the Schildt book it does the following:
(double)operand
What is the difference, and which one is better to use?
Printable View
In the Deitel book it tells me to cast as follows:
static_cast< double >( operand )
Yet in the Schildt book it does the following:
(double)operand
What is the difference, and which one is better to use?
Static_cast is a C++ style of casting. It's a restricted version of its C counterpart; it will only convert between related pointer types. It is possible to cast pointers up and down the inheritance hierarchy, but not to a type outside of the hierarchy. Because of that checking feature, static_cast is the better one. (C++ for game programmers )
>> it will only convert between related pointer types
Not quite. It'll convert between related types: pointers within the same class hierarchy, integral and enum types, floating point and integral types, etc.
> In the Deitel book it tells me to cast as follows:
> static_cast< double >( operand )
No doubt it will go on to explain about dynamic_cast, const_cast etc...
This is very much the preferred way in new C++