Relative Content

Tag Archive for include

cpp and h/hpp #include: “why” question

Why does the source include a header and not also the other way around? I googled it but only found questions regarding the use of header files, how to include them but nowhere to say why it is like it is.
If the header is merely the declaration, how does the compiler know the definition only from it?
For example: take foo.cpp, bar.h, bar.cpp. This is what everybody does:
in foo.cpp:
#include "bar.h"
but the bar.cpp is not included neither in the bar.h or foo.cpp. That’s why I deem logical that bar.cpp be included in bar.h and so, indirectly in foo.cpp.