Here is a section on #include
's from Google's C++ style guide:
If you rely on symbols from bar.h, don't count on the fact that you included foo.h which (currently) includes bar.h: include bar.h yourself, unless foo.h explicitly demonstrates its intent to provide you the symbols of bar.h.
However, any includes present in the related header do not need to be included again in the related cc (i.e., foo.cc can rely on foo.h's includes).
When I read this, these sentences seem to contradict. To me they say:
- If
foo.cc
needs stuff inbar.h
, it must includebar.h
. - If
foo.cc
needs stuff inbar.h
, andfoo.cc
includesfoo.h
, andfoo.h
includesbar.h
, thenfoo.cc
doesn't need to includebar.h
.
Why don't these sentences contradict?