在 C++11 中的函数声明如下:
int f(void);
意思相同:
int f();
A parameter list consisting of a single unnamed parameter of non-dependent type void is equivalent to an empty parameter list.
我得到(可能是错误的)印象,这是一个旧功能,可能是从 C 继承的?
有人知道以这种方式声明无参数函数的历史或原理吗?
最佳答案
在 C++ 中,它们的含义相同。
在 C 中 f(void)
与 f()
不同,因为 f()
的意思是“未指定的参数”——你可以合法地传递任何东西(接收数据的函数是否对此感到满意是另一回事)。
关于c++ - `f(void)` 表示 C++11 或 C 中没有参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18376783/