在 C++ Boost 库中,为什么有一个“.ipp"?一些头文件的扩展名
在 C++ Boost 库中,为什么某些头文件上有.ipp"扩展名?
In the C++ Boost libraries, why is there a ".ipp" extension on some header files?
它们似乎是包含在同名.hpp"文件中的头文件.
It seems like they are header files included by the ".hpp" file of the same name.
这个约定在 Boost 之外很常见吗?
Is this convention common outside of Boost?
拥有特殊文件类型的理由是什么?
What is the justification for having a special file type?
推荐答案
来自一位模板大师的解释:
如果您想将模板源拆分为界面和实施(有很多很好的理由这样做,包括控制实例化),你不能很好地使用相同的名称(foo.hpp) 两次,foo.cpp 不适合任何一个.foo.ipp 清楚地将该文件描述为一个实现文件,旨在#included 在 foo.hpp 中.
If you want to split up your template sources into interface and implementation (there are lots of good reasons to do that, including controlling instantiation), you can't very well use the same name (foo.hpp) twice, and foo.cpp wouldn't be appropriate for either one. foo.ipp clearly delineates the file as an implementation file intended to be #included in foo.hpp.
相关文章