`F(无效)`这意味着在C ++ 11或C没有paramters? [英] `f(void)` meaning no paramters in C++11 or C?

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

问题描述

在C ++ 11下面的函数声明:

  INT F(无效);

意思是一样的:

  INT F();


  

由非依赖型空单未命名参数的参数列表相当于空参数列表。


我得到的(也许是假的)IM pression这是一个古老的功能,也许是从C继承?

有谁知道这样的历史背景和理由来声明函数不带参数?


解决方案

在C ++中他们都意味着同样的事情。

在C F(无效) F(),becuse ˚F不同()表示未指定的参数 - 你可以合法地通过任何东西(在接收数据的功能是否感到高兴与否是另一回事)。

In C++11 the following function declaration:

int f(void);

means the same as:

int f();

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

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?

解决方案

In C++ they both mean the same thing.

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(无效)`这意味着在C ++ 11或C没有paramters?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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