在没有参数的函数中使用void? [英] Using void in functions without parameter?
问题描述
void
,例如: class WinMessage
{
public:
BOOL Translate(void);
};
是多余的,您可能只需编写 我自己通常包含它,因为当代码完成支持IDE显示 我的问题是,将 等同于: 第一个样式仍然可以合法编写的事实可归因于C. 更改:在C ++ ,一个用空参数列表声明的函数需要 在C中,一个空参数列表表示数字和 在C语言中,避免不需要的未知含义是有意义的。在C ++中,这是多余的。 简短的回答:在C ++中,这是C编程过多的后遗症。这就把它放在不要这样做,除非你真的必须在我的视图中支持C ++。 In C++ using is redundant, you might as well just write I, myself generally include it since it's a bit helpful when code-completion supporting IDEs display a My question is, Is adding In C++ is identical to: The fact that the first style can still be legally written can be attributed to C. Change: In C++, a function declared with an empty parameter list takes
no arguments. In C, an empty parameter list means that the number and
type of the function arguments are unknown. Example:
In C, it makes sense to avoid that undesirable "unknown" meaning. In C++, it's superfluous. Short answer: in C++ it's a hangover from too much C programming. That puts it in the "don't do it unless you really have to" bracket for C++ in my view. 这篇关于在没有参数的函数中使用void?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! Translate(); < code $。
void $时它有点帮助c $ c>,因为它确保了该函数绝对不会有参数。
void
添加到无参数函数是一种好的做法吗?在现代代码中是否应该鼓励它?
void f(void);
void f();
n3290§C.1.7(C ++和ISO C兼容)指出:
$ b blockquote>
没有参数。
类型
$ b $ p $ int f( ); //表示C ++中的int f(void)
// int f(未知)中的C
void
in a function with no parameter, for example:class WinMessage
{
public:
BOOL Translate(void);
};
Translate();
.void
, since it ensures me that the function takes definitely no parameter. void
to parameter-less functions a good practice? Should it be encouraged in modern code?void f(void);
void f();
n3290 § C.1.7 (C++ and ISO C compatibility) states:
int f(); // means int f(void) in C++
// int f( unknown ) in C