*.h or *.hpp for your class definitions(*.h 或 *.hpp 用于您的类定义)
问题描述
我一直使用 *.h
文件作为我的类定义,但在阅读了一些 boost 库代码后,我意识到它们都使用 *.hpp
.我一直讨厌那个文件扩展名,我想主要是因为我不习惯它.
I've always used a *.h
file for my class definitions, but after reading some boost library code, I realised they all use *.hpp
. I've always had an aversion to that file extension, I think mainly because I'm not used to it.
使用*.hpp
相对*.h
有什么优缺点?
What are the advantages and disadvantages of using *.hpp
over *.h
?
推荐答案
以下是 C 和 C++ 头文件命名不同的几个原因:
Here are a couple of reasons for having different naming of C vs C++ headers:
- 自动代码格式化,对于格式化 C 和 C++ 代码,您可能有不同的准则.如果标题由扩展名分隔,您可以将编辑器设置为自动应用适当的格式
- 命名,我参与过一些项目,其中有用 C 编写的库,然后用 C++ 实现了包装器.由于标头通常具有相似的名称,即 Feature.h 与 Feature.hpp,因此它们很容易区分.
- 包含,也许您的项目有更合适的可用 C++ 编写的版本,但您使用的是 C 版本(见上文).如果标头以实现它们的语言命名,您可以轻松发现所有 C 标头并检查 C++ 版本.
请记住,C 不是 C++,除非您知道自己在做什么,否则混合搭配可能非常危险.适当地命名您的来源可以帮助您区分语言.
Remember, C is not C++ and it can be very dangerous to mix and match unless you know what you are doing. Naming your sources appropriately helps you tell the languages apart.
这篇关于*.h 或 *.hpp 用于您的类定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:*.h 或 *.hpp 用于您的类定义


- 近似搜索的工作原理 2021-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 静态初始化顺序失败 2022-01-01
- 从python回调到c++的选项 2022-11-16
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- C++ 协变模板 2021-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01