In the C++ Without Fear: A Beginner's Guide That Makes You Feel Smart book, and in chapter (8), it mentions the following about reinterpret_cast
….converts from one pointer type (int) to another (char*). Because the cast changes the way the data pointed to is interpreted, it is called reinterpret_cast, as opposed to static_cast.*
Can you describe this paragraph here? Especially the reason for the way the operation is named?
Thanks.
Best Answer
Basically,
reinterpret_cast
reinterprets the bit pattern at a specific location as a different type.See for example here: http://publib.boulder.ibm.com/infocenter/lnxpcomp/v7v91/index.jsp?topic=%2Fcom.ibm.vacpp7l.doc%2Flanguage%2Fref%2Fclrc05keyword_reinterpret_cast.htm
A
static cast
converts the argument instead of just reinterpreting it. You can try this out by static_casting anint
tofloat
and reinterpret_casting anint
tofloat
. The result will be totally different.