C ++转换为空 [英] C++ cast to void
问题描述
据我了解,C ++标准指出,仅在函数样式转换( ISO / IEC 14882:2003,5.2.3 )的情况下,转换为void才是正确的。
但是我找不到有关 C风格强制转换为 C ++ 标准的任何信息。
在这种情况下,程序的行为是否仅是实现定义的?
< blockquote>
据我所知,C ++标准表示强制转换为 void
仅在函数样式强制转换的情况下
否,可以通过 static_cast
完成,因此也可以通过使用功能或强制转换表示法进行转换。 / p>
但是我在C ++中找不到有关C样式转换为
void
的任何信息
[expr.static.cast]为 static_cast
定义,5.2.9 / 6:
任何表达式都可以显式转换为 cv
void
,在这种情况下它将成为一个废弃值
表达式。
[expr .cast](5.4版)介绍了C样式的强制转换如何使用 static_cast
,因此它也适用于该样式。 [expr.type.conv],5.2.3描述了功能样式如何等效于C样式,因此它也适用于该样式。
(注意:章节编号指的是C ++ 11(ISO / IEC 14882:2011),而不是您所指的C ++ 03,因为这是当前版本。其他版本可能有所不同,但可能不大。
As I understand, C++ standard says that casting to void is correct only in case of function-style casting (ISO/IEC 14882:2003, 5.2.3).
But I can't find anything about C-style casting to void in C++ standard.
Is behavior of program only implementation-defined in this case ?
As I understand, C++ standard says that casting to
void
is correct only in case of function-style casting
No, it can be done by static_cast
, and therefore also by conversions using functional or cast notation.
But I can't find anything about C-style casting to
void
in C++ standard.
It's defined for static_cast
by [expr.static.cast], 5.2.9/6:
Any expression can be explicitly converted to type cv
void
, in which case it becomes a discarded-value expression.
[expr.cast], 5.4, describes how a C-style cast can use static_cast
, so it's also valid for that style. [expr.type.conv], 5.2.3, described how functional style is equivalent to C-style, so it's also valid for that style.
(Note: section numbers refer to C++11 (ISO/IEC 14882:2011), not C++03 which you refer to, since that's the current version. Other versions may differ, but probably not much.)
这篇关于C ++转换为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!