SF.3: Use .h files for all declarations used in multiple source files
SF.3:使用.h文件管理所有在多个源文件中使用的声明
Maintainability. Readability.
维护性。可读性。
Example, bad(反面示例)
// 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(实施建议)
原文链接
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#sf3-use-h-files-for-all-declarations-used-in-multiple-source-files