Re: accessing a library
"Carmen Sei" wrote:
And header files are not about inheritance. They simply declare
the
existence of other items so the compiler will know their type.
if main.cpp make use of the all 4 header files, should I include
all 4
header files again in main.cpp to remind others that it has used
objects defined in those 4 header files?
It depends on the design of a project. Although Scott is right
that header files are not about inheritance, there is some
hierarchy (which is not enforced by the language in any way, this
is important).
I don't know how exactly Java compiler parses the "import"
directive, but C++ compiler is very straightforward about
#include's.
All strings in a .CPP source file that start at the beginning of a
line with symbol '#' are preprocessor directives. Long time ago
there were two distinct tools: preprocessor and compiler. Nowadays
the compiler does the job of a preprocessor as well, however
logical distinction still persists.
So, before .CPP file is compiled all preprocessor directives
executed, i.e. entire content of a file specified in #include
directive is inserted into .CPP file, all macros in the code are
expanded etc. As a result of this operation you get one big file
called "translation unit". This resulting translation unit is what
actually goes to the compiler.
Although it's not important for the compiler how header files end
up in a final translation unit, you, as a project designer, should
carefully think out project's code organization. Otherwise include
chain becomes all messed up an hard to manage. This is very common
problem of big projects, especially when several developers work
on the same project.
HTH
Alex