On 6/5/15 8:03 AM, Louis Krupp wrote:
>
> <string> is required, it seems, but if it happens to be #included by
> <iostream> or <ostream>, then the program compiles without explicit
> inclusion. It's not a good idea, though; it would be too easy for
> another programmer to move the 'cout' somewhere else, remove the
> <ostream> and <stream> #includes, and then be surprised when the
> remaining code doesn't compile.
>
> Louis
>
In C, the language standard prohibits one system header from "randomly"
injecting names from other headers into the namespace, effectively
prohibiting one system header from including another defined system
header (they need to include "private" headers using symbols reserved
for the implementation for inter-header dependencies.
In C++, this doesn't work, so headers are allowed to include other
headers. The fundamental difference is that in C, type names don't
really matter. Code doesn't care if a type name is an actual struct or a
typedef for such a struct. In C++, it matters.
Yes, Good Practices say you should explicitly include what you use, and
not depend on indirect dependencies, but the language standard doesn't
provide any way it enforce such a rule.