前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >C++核心准则SF.3:使用.h文件管理所有在多个源文件中使用的声明

C++核心准则SF.3:使用.h文件管理所有在多个源文件中使用的声明

作者头像
面向对象思考
发布2020-10-10 10:06:07
8370
发布2020-10-10 10:06:07
举报
文章被收录于专栏:C++核心准则原文翻译

SF.3: Use .h files for all declarations used in multiple source files

SF.3:使用.h文件管理所有在多个源文件中使用的声明

Reason(原因)

Maintainability. Readability.

维护性。可读性。

Example, bad(反面示例)

代码语言:javascript
复制
// bar.cpp:
void bar() { cout << "bar\n"; }

// foo.cpp:
extern void bar();
void foo() { bar(); }

A maintainer of bar cannot find all declarations of bar if its type needs changing. The user of bar cannot know if the interface used is complete and correct. At best, error messages come (late) from the linker.

如果需要修改bar的类型,维护者无法找到bar的所有声明。bar的用户无法知道所用的接口是否完全和正确。

Enforcement(实施建议)

  • Flag declarations of entities in other source files not placed in a .h.
  • 标记实体的定义没有放在.h文件中而放在其他源文件中的情况。

原文链接

https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#sf3-use-h-files-for-all-declarations-used-in-multiple-source-files

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

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

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

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

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Reason(原因)
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档