f(void)意味着C ++ 11或C中没有参数? [英] `f(void)` meaning no parameters in C++11 or C?

查看:88
本文介绍了f(void)意味着C ++ 11或C中没有参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++ 11中,以下函数声明:

In C++11 the following function declaration:

int f(void);

意思是:

int f();




由单个非依赖类型的未命名参数组成的参数列表void等于一个空的参数列表。

A parameter list consisting of a single unnamed parameter of non-dependent type void is equivalent to an empty parameter list.

我得到(也许是错误的)印象,这是一个旧功能,也许是从C继承的?

I get the (perhaps false) impression this is an old feature, perhaps inherited from C?

有人知道这种方法的历史或基本原理来声明不带参数的函数吗?

Does anyone know the history or rationale behind this way to declare a function with no parameters?

推荐答案

在C ++中,它们的含义相同。

In C++ they both mean the same thing.

在C中 f(void) f(),因为 f()的意思是未指定的参数-您可以合法地传递任何内容(接收数据的函数对此是否满意是另一回事) 。

In C f(void) is different from f(), becuse f() means "unspecified parameters" - you can legally pass anything (whether the function at receiving the data is happy about that or not is another matter).

这篇关于f(void)意味着C ++ 11或C中没有参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆