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?
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 )
source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense
>> 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.
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
> 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++
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.