是F(无效)德$ P $在现代的C和C ++ pcated [英] is f(void) deprecated in modern C and C++

查看:149
本文介绍了是F(无效)德$ P $在现代的C和C ++ pcated的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在重构/整理在C ++项目中使用的一些旧的C code和定期看功能,例如:

I'm currently refactoring/tidying up some old C code used in a C++ project, and regularly see functions such as:

int f(void)

我往往会为写:

int f()

是否有任何理由不更换(无效)和()在整个codeBase的,以提高一致性,或者是有,我不知道两者之间的细微差别?更具体地,如果C ++中的虚拟成员函​​数被描述为:

Is there any reason not to replace (void) with () throughout the codebase in order to improve consistency, or is there a subtle difference between the two that I am unaware of? More specifically, if a virtual member function in C++ is described as:

virtual int f(void)

和派生类包含一个成员函数:

and a derived class includes a member function:

int f()

这是一个有效的覆盖?另外,我很可能会遇到的基础上几乎相同签名的任何连接问题?

is this a valid override? Additionally, am I likely to encounter any linker problems based on almost identical signatures?

推荐答案

在C,声明 INT F(无效)表示函数返回int不带参数。声明 INT F()表示函数返回int可以接收任意数量的参数。因此,如果你有一个函数,C中没有参数,前者是正确的雏形。

In C, the declaration int f(void) means a function returning int that takes no parameters. The declaration int f() means a function returning int that takes any number of parameters. Thus, if you have a function that takes no parameters in C, the former is the correct prototype.

在C ++中,我相信 INT F(无效)是德precated和 INT F()为preferred,因为它具体是指一个函数,没有参数。

In C++, I believe int f(void) is deprecated, and int f() is preferred, as it specifically means a function that takes no parameters.

这篇关于是F(无效)德$ P $在现代的C和C ++ pcated的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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