.h
and .cc
files come in pairs
.h和.cc文件成对出现
This is an overflow page for this style rule.
这是此样式规则的溢出页。
Example violations
这是此样式规则的溢出页。
Example violations, which should be avoided in new code:
新代码中应避免的违规示例:
- Declarations in
path/to/include/foo.h
, definitions inpath/to/source/foo.cc
. Fix: The.h
and.cc
files should be in the same directory. path/to/include/foo.h
中的声明,path/to/source/foo.cc
中定义。修复:.h和.cc文件应该在同一目录中。- Declarations in
foo.h
, definitions in bothfoo_bar.cc
andfoo_baz.cc
. Fix: The.h
and.cc
files should come in pairs, so either splitfoo.h
intofoo_bar.h
andfoo_baz.h
, or mergefoo_bar.cc
andfoo_baz.cc
intofoo.cc
. - foo.h中的声明,foo_bar.cc和foo_baz.cc中定义。修复:.h和.cc文件应该成对出现,所以要么将foo.h拆分为foo_bar.h和foo_barz.h,要么将foo_bar.cc和foo_bazi.cc合并为foo.cc。
Exception for platform-specific code
平台特定代码的异常
If the functions in a header file need different implementations for different platforms, we allow the following arrangement:
如果头文件中的函数需要针对不同平台进行不同的实现,我们允许以下安排:
- Declarations in
foo.h
. - foo.h中的声明。
- A complete set of matching definitions in
foo_win.cc
, another complete set of matching definitions infoo_mac.cc
, and so on. - foo_win.cc中的一整套匹配定义,foo_mac.cc中的另一套完整匹配定义,依此类推。
- As per the main rule, these files should all be in the same directory and in the same build target. The build target should use platform conditionals to ensure that exactly one of the
.cc
files are included. - 根据主要规则,这些文件都应该在同一目录中,并且在同一构建目标中。构建目标应该使用平台条件来确保只包含一个.cc文件。