reinterpret_cast [英] reinterpret_cast
问题描述
在 C ++ Without Fear:A Beginner's Guide that Make You Feel Smart 书中,在第(8)节中,它提到了以下关于 reinterpret_cast
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
....从一个指针类型(int )转换为另一个指针类型(char *)。因为转换改变了数据指向的方式,所以它被称为reinterpret_cast,而不是static_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?
谢谢。
推荐答案
基本上,reinterpret_cast会将特定位置的位模式重新解释为不同的类型。
Basically, the reinterpret_cast reinterprets the bit pattern at a specific location as a different type.
reinterpret_cast操作符生成一个与其参数具有相同位模式的新类型的值。
"The reinterpret_cast operator produces a value of a new type that has the same bit pattern as its argument."
静态转换转换参数,而不是仅仅重新解释它。你可以通过static_casting和int来尝试这个,float和reinterpret_casting int。结果将完全不同。
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.
这篇关于reinterpret_cast的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!