One of the new-style casting operators of C++ (the others are
reinterpret_cast<T>(o) is the same as saying
(T)o. The result will be of type
T. In particular, it always compiles (unlike the other casts) and it always succeeds at runtime (unlike
reinterpret_cast only when you have no other choice. This is what you use to do the really ugly, "down-to-the-metal" casts in the bowels of particularly hairy code. Use it to do things like cast between an integer and a pointer (implementation defined according to ISO C++, but nonetheless sometimes necessary). Uggh.
The other casting operators have no parallel in ISO C, but
(T); why add it?
Three reasons; at least the first two are Bjarne Stroustrup's:
- It's much uglier, which is fitting for an ugly operation.
- It's much easier to
- It's consistent with the other three predefined syntaxes (and will be consistent with any additional user-defined syntaxes, which might exist e.g. for converting smart pointers).