Alf P. Steinbach posted:
* Adam:
The former is defined to mean the same as the latter, as an isolated
expression.
I was very surprised to hear that!
I would've thought that the former was a static_cast (which could also
call explicit contructors), and that the latter was a reinterpret_cast.
But to my horror, the following compiled:
int main()
{
typedef char* PC;
PC p;
p = PC(43);
}
I'll think twice before using the "function" form in future.
I think most people shy away from using the new casts (static_cast,
dynamic_cast, reinterpret_cast, const_cast) because they're just too many
characters to type (I often find myself thinking "aw crap I've to write
that entire word out"). Lately I've been using typedef's for unwieldy
names like "unsigned char", peferring "uchar" in its place. I might start
using the likes of: scast, dcast, rcast, ccast. Would #define be the best
way to do this?
#define scast static_cast
#define rcast reinterpret_cast
#define dcast dynamic_cast
#define ccast const_cast
-Tomás