C ++投射为零

编程入门 行业动态 更新时间:2024-10-27 00:31:28
本文介绍了C ++投射为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你好, 以下陈述是合法的(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 ++投射为零

本文发布于:2023-11-26 19:36:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634920.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:为零

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!