Slime wrote:
>> (classes and template parameters). However, I don't think anyone is
>> interested in another C++ lecture of mine... :P
>
> On the contrary, I like reading them =)
>
> Wouldn't the real C++ way be something like
>
> reinterpret_cast<int>(some_double)
>
> Or something like that? Not sure what type of cast it would be.
>
The "correct C++ way" would be to use static_cast<int>().
This is because reinterpret_cast<>() will not change the binary
representation while doing the cast (and is hence meant for potentially
dangerous casts). Since casting a double into an int does require
a change in the binary representation (usually 8 byte floating point
into 4 byte integer), reinterpret_cast<>() cannot be applied.
The compiler should give an error in this case.
Wolfgang
Post a reply to this message
|