明确定义包含或允许传播 [英] Explicitly defining includes or allowing propagation
问题描述
这是一个关于最佳实践的快速问题。假设我有以下文件:
啊
Bh
Ch
以下代码:
啊:
Hi,
Just a quick question regarding the best practice for this. Let's say I have the following files:
A.h
B.h
C.h
And the following code:
A.h:
class A
{
}
Bh:
B.h:
#include "A.h"
class B
{
private:
A a;
}
Ch:
C.h:
#include "A.h" // ?
#include "B.h"
class C
{
private:
A a;
B b;
}
由于C包含B而B包含A,这意味着C可以访问A.但是,如您所需由于对编译时间有潜在的巨大影响,要小心C ++标题,明确说C包含A还是允许它通过B传播它会更好?
虽然更多的标题意味着更混乱,但我宁愿明确定义它是否可以作为改善编译时间的捷径。
我有什么尝试过:
没什么,只是征求意见。
As C includes B and B includes A, that means C can access A. However, as you need to be careful with C++ headers due to the potentially massive impact on compilation time, would it be better to explicitly say that C includes A, or allow it to propagate that via B?
Although more headers means more clutter, I'd rather explicitly define it if it will act as a shortcut to improve compilation time.
What I have tried:
Nothing, just asking for advice.
推荐答案
因为标题必须是无论如何防止多次包含,我认为没有对编译时间的相关影响(作为旁注,使用预编译的头来加速编译)。因此,在我看来,这只是个人品味的问题。
Since headers must be anyway guarded against multiple inclusion, I see no relevant impact on compilation time (as a side note, use precompiled headers to speed up compilation). Hence it is just matter of personal taste, in my opinion.
这篇关于明确定义包含或允许传播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!