In C++, static_cast(some_double) converts some_double to an int. In general, C++-style casts are safer than the C-style casts because they make explicit the intent of the cast. However, when converting a double to an int, is there any reason to use static_cast rather than using int's constructor: int(some_double)?
I see static_cast used like this
(
Read more... )
Comments 2
If you care about correctness more than performance, boost::numeric_cast seems like it might be the right choice. Otherwise, I'd say go for the constructor syntax.
Reply
I agree with the grepping argument for C++ casts but I think I like them most because they reflect the intention of the programmer. I also like C++-style casts because they are verbose (since casting is bad, casts should look kludgy).
I think I'll stick with the constructor form.
Reply
Leave a comment