且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

什么是“void();”作为一个单独的语句意味着C ++?

更新时间:2023-11-08 20:20:58

void 类型是且始终是特殊的。它确实是不完整的,但是在许多情况下是允许的,其中通常期望完整类型。否则,例如,由于 void 类型的不完整性, void 函数的定义将无效。也可以编写 void 类型的表达式(对 void 函数的任何调用都是这种表达式的示例) 。

void type is and has always been special. It is indeed incomplete, but it is allowed in many contexts where a complete type is typically expected. Otherwise, for one example, a definition of a void function would be invalid because of incompleteness of void type. It is also possible to write expressions of void type (any call to a void function is an example of such expression).

即使在C语言中,也可以使用 void 的直接表达式)0 。你在代码中有什么只是一个C ++特定的语法的例子,它基本上是一样的事情:它产生类型 void 的无操作表达式。

Even in C language you can use immediate expressions of void type like (void) 0. What you have in your code is just an example of C++-specific syntax that does essentially the same thing: it produces a no-op expression of type void.