benben wrote:
A source file, of course, must contain all information necessary either by
#including corresponding headers or having it as part of the file.
Generally, if something in a source is not declared before use, you won't be
able to compile it.
An "include file" is declaration and protected againts
multiple includes by a include guard, right?
Consider the following two rudimentary include files:
IncludeA.h:
-----------
#include <string>
class A;
IncludeB.h:
-----------
#include "IncludeA.h"
class B {
public:
A a;
string name;
};
I would claim it as an error for IncludeB.h *NOT* to include
<string> as its declaration (B) depend on the string concept.
You don't get a compiler error nor warning (perhaps a warning
would be appropriate) by nut including it, as <string> is
included indirectly through IncludeA.
This is a common knowlegde and most styleguides will suggest
you include <string> in this case to stay independent of internal
changes in IncludeA.
My question is if this should be the case also for difinition
files (.c++ files)? You may claim that by including the declaration
"IncludeA", you inherit the lot, and there is no need to include
<string> separately as you got it for free already.
Any suggestions?
Thanks!