For example the following cast can be found littered throughout the MSDN documentation:
(LPTSTR)&lpMsgBuf
Should I bother converting that to:
static_cast<LPTSTR>(&lpMsgBuf);
Or should I just leave all the idiomatic C-esque Win32 portions as they are typically found in the docs, and save the more idiomatic C++ style/usage for the rest of my code?
New style casts were introduced for a reason: they're safer, more explanatory/self-commenting, easier to see, and easier to grep for.
So use them.
By more explanatory, we mean that you can't just cast to something, you have to say why you're casting (I'm casting in an inheritance hierarchy (dynamic_cast), my cast is implementation defined and possibly not portable (reinterpret_cast), I'm casting away constness (const_cast), etc.).
They're purposefully long and ugly so that the cast jumps out at the reader (and to discourage a programming style that employs too much casting).
They're safer because, e.g., you can't cast away constness without explicitly doing that.
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