c++
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.
Basically, the 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
"The reinterpret_cast operator produces a value of a new type that has the same bit pattern as its argument."
The static cast converts the argument instead of just reinterpreting it. You can try this out by static_casting and int to float and reinterpret_casting an int to float. The result will be totally different.
There's nothing fancy here. it's really just intended to reinterpret something.
From standard 5.3.10, reinterpret_cast is aimed to cater the following cases:
尝试阅读本文:http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=134
链接地址: http://www.djcxy.com/p/73762.html上一篇: C ++
下一篇: C ++