你好, 以下陈述是合法的(0是实际的 a指针参数,可能是''0'和相关的 演员)? MyClass * p = reinterpret_cast< MyClass *>(0); MyClass * p = static_cast< MyClass *>(0); 谢谢和致以最诚挚的问候, 文杰
Hello, Is the following statements legal (0 is actualy a pointer parameter that could be ''0'' and relevant to the casts) ? MyClass* p = reinterpret_cast<MyClass*>(0); MyClass* p = static_cast<MyClass*>(0); Thanks and best regards, Wenjie
推荐答案2003年8月17日01:54: 20 -0700, go****@yahoo (文杰)写道: On 17 Aug 2003 01:54:20 -0700, go****@yahoo (Wenjie) wrote: 以下陈述是否合法(0是实际的指针参数,可能是'0''并且与演员相关)? MyClass * p = reinterpret_cast< MyClass *> ;(0); MyClass * p = static_cast< MyClass *>(0); Is the following statements legal (0 is actualya pointer parameter that could be ''0'' and relevantto the casts) ?MyClass* p = reinterpret_cast<MyClass*>(0);MyClass* p = static_cast<MyClass*>(0);
这不是问题。 有什么问题?
That''s not the problem. What is the problem?
Wenjie写道: 你好, 是以下的政治家ts legal(0是实际的一个指针参数,可能是'0''并且与演员相关)? MyClass * p = reinterpret_cast< MyClass *>(0); MyClass * p = static_cast< MyClass *>(0); Hello, Is the following statements legal (0 is actualy a pointer parameter that could be ''0'' and relevant to the casts) ? MyClass* p = reinterpret_cast<MyClass*>(0); MyClass* p = static_cast<MyClass*>(0);
你想做什么?如果你想要一个所谓的NULL指针,那么就忘记 reinterpret_cast。为什么?因为那个是实现定义的。 并且NULL指针实现不一定是具有与包含零的整数相同的实现的指针。关于第二个演员:: 它是不必要的。 0本身将自动转换为NULL指针 的正确类型。 WW aka Attila
What do you want to do? If you want a so-called NULL pointer, then forget the reinterpret_cast. Why? Because that one is implementation defined. And a NULL pointers implementation is not necessarily a pointer having the same implementation as an integer containing zero. About the second cast:: it is unecessary. The 0 itself will automagically convert to a NULL pointer of the right type. WW aka Attila
Wenjie写道: Wenjie wrote: 你好, 以下陈述合法 是的,虽然结果第一个是实现定义。 (0实际上是一个指针参数,可能是'0''并且与演员相关)? 我不明白。 MyClass * p = reinterpret_cast< MyClass *>(0); 如果你想要一个空指针,请注意上面并不一定是导致一个。它_might_导致一个所有位为零的指针,并且 指针_might_是一个空指针,但是不能保证。 MyClass * p = static_cast< MyClass *>(0); Hello, Is the following statements legal Yes, though the result of the first is implementation defined. (0 is actualy a pointer parameter that could be ''0'' and relevant to the casts) ? I don''t understand that. MyClass* p = reinterpret_cast<MyClass*>(0); If you wanted a null pointer, note that the above doesn''t necessarily lead to one. It _might_ lead to a pointer with all bits zero, and that pointer _might_ be a null pointer, but that''s not guaranteed. MyClass* p = static_cast<MyClass*>(0);
这与以下相同: MyClass * p = 0; 使得pa空指针。
This is the same as: MyClass* p = 0; which makes p a null pointer.
更多推荐
C ++投射为零
发布评论