前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >C++核心准则​NL.25:不要将void用作参数类型

C++核心准则​NL.25:不要将void用作参数类型

作者头像
面向对象思考
发布2020-12-15 15:01:50
3700
发布2020-12-15 15:01:50
举报
文章被收录于专栏:C++核心准则原文翻译

NL.25: Don't use void as an argument type

NL.25:不要将void用作参数类型

Reason

It's verbose and only needed where C compatibility matters.

它很冗长,只有在C兼容性很重要的情况下才需要这么做。

Example(示例)

代码语言:javascript
复制
void f(void);   // bad

void g();       // better
Note(注意)

Even Dennis Ritchie deemed void f(void) an abomination. You can make an argument for that abomination in C when function prototypes were rare so that banning:

哪怕丹尼斯·里奇也认为void f(void)是可憎的。当函数原型很少见时,您可以为C中的可憎性辩护,因此禁止:

代码语言:javascript
复制
int f();
f(1, 2, "weird but valid C89");   // hope that f() is defined int f(a, b, c) char* c; { /* ... */ }

would have caused major problems, but not in the 21st century and in C++.

会造成重大问题,但不会在21世纪和C ++中引起。

原文链接

https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#nl25-dont-use-void-as-an-argument-type

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-12-04,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 面向对象思考 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • NL.25: Don't use void as an argument type
  • Reason
    • Note(注意)
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档