*.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 用于您的类定义
基础教程推荐
- 从 std::cin 读取密码 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07