
old style casts vs new style casts
Quote:
> First, what is exactly "old style cast"?
Old-style cast, aka C-style cast, is a construct of the form
(Type)expression, as in
int i;
char *p = (char*)i;
Quote:
> Why are they worse than new style casts like static_cast?
Because new-style casts show your intention more clearly, and you are
less likely to do more than you have intended. You can cast away
constness with const_cast or with old-style cast, but const_cast is
clearer, essentially self-documenting, and won't allow you to
accidentally cast to a different type.
Quote:
> Because they don't throw exceptions?
Only dynamic_cast can throw exceptions, and it is in a different league
anyway, because there is no old-style equivalent.
Quote:
> Why reinterpret_cast still used in ATL7.0 source code even though MSDN
> recommends to use it as a last resort?
reinterpret_cast is often unavoidable in Windows programming. E.g. many
Windows messages expect pointers passed as LPARAM. COM functions often
have void** parameter where you need to pass SomeInterface**.
--
With best wishes,
Igor Tandetnik
"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken