C++ 之间的头文件名一致图书馆
在我的项目中,我使用两个库,v8 和 提升。 Boost 使用 .hpp
扩展名作为其标头,而 v8 使用 .h
扩展名作为其标头。
归根结底,我的源代码是这样开始的:
#include "v8.h"
#include "boost/filesystem.hpp"
...
在我问到这个主题的其他问题中,一般答案是没关系,但我只是应该在名称之间保持一致。
这段代码编译得很好,但是,编码风格/标准 - 可以吗?这个问题有什么解决方案吗(比如以某种方式自动将所有 .hpp
更改为 .h
?)
谢谢。对于那些愚蠢的问题感到抱歉。
In my project I use two libraries, v8 and boost. Boost uses the .hpp
extension for its headers, while v8 uses the .h
extension for its headers.
In the end of day, my source code starts like that:
#include "v8.h"
#include "boost/filesystem.hpp"
...
In other question I asked about this subject, the general answer was that it is okay, but I just should be consistent between names.
This code compiles well, but, coding styles/standards - is it okay? Is there any solution for this problem (like changing all .hpp
to .h
automatically somehow?)
Thanks. And sorry for those stupid questions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不用担心不一致,没关系。太多的时间常常被花在这些细节上,每个人都对此感到内疚。
只要与您自己的编码标准保持一致即可。
您最终将使用一些第三方库或几个使用与您不同约定的库。您对此无能为力,而且您使用的其中两个库通常会与您的标准以及彼此之间发生冲突。这不仅适用于包含扩展,还适用于诸如
function_that_does_something
与FunctionThatDoesSomthing
之类的命名约定。这很好。我绝对强烈建议不要尝试更改其他人的库以适应您的编码标准。例如,将 boost .hpp 重命名为 .h。这是一个坏主意,当您想升级到该库的新版本时,这将是一场噩梦。
花时间以更优雅的方式解决您正在解决的问题,而不是担心这样的细节。
Don't worry about the inconsistency, it doesn't matter. Too much time is often spent obsessing about such details, and everyone is guilty of it.
Just be consistent with your own coding standards.
You'll eventually use some 3rd party library or several that use different conventions than you. There's nothing you can do about it, and often 2 of those libraries you use will be conflicting with your standards and with each other. That's not only for include extensions, but also for naming convetions like
function_that_does_something
vsFunctionThatDoesSomthing
.It's fine.I would definitely strongly advice against trying to change someone else's library to fit into your coding standard. I.e. for example renaming boost .hpp to .h. This is a bad idea and when you want to upgrade to newer versions of the library it will be a nightmare.
Spend your time solving the problem you're solving in a more elegant way rather than worrying about details like this.
没关系。编码标准并没有真正涉及其中,因为您必须遵循所提供的内容。如果 v8 人员仅提供
.h
而 boost 人员仅提供.hpp
那么,无需将一组文件复制到另一个选择或提供您自己的包装器头文件,你的选择很少。这两个选项都有其缺点和真正可疑的好处,因此我不会担心必须包含两个不同的文件扩展名这一事实。
It's fine. Coding standards don't really come into it since you have to go with what you're given. If the v8 people only provide
.h
and the boost people only provide.hpp
then, short of copying one set of files to the other choice or providing your own wrapper header files, you have few options.Both of those option have their downsides for what is really dubious benefits, so I wouldn't concern yourself with the fact that you have to include two different file extensions.