If you don't intend to become a C++ guru in a couple of days and hack each and every word in a C++ cookbook (which may contain errors or vague phrases) just get over it because it's a minor thing.
Headers... :
1 2 3 4 5
|
//a.h
void f();
void g();
int h();
class w{};
|
1 2 3
|
//b.h
class w1{};
int a;
|
1 2 3 4 5 6 7 8 9 10
|
//main.cpp
#include "b.h"
#include "a.h"
int c;
int main()
{
//....
}
|
main.cpp will be the first file to be processed by the compiler, because it has the main() function which is the entry point of the application. It starts from top. include a.h -> it will include all that's there, verbatim! same for b.h.
The compiler sees the 3 pieces of code above like this (one big program):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
//main.cpp
//b.h
class w1{};
int a;
//a.h
void f();
void g();
int h();
class w{};
int c;
int main()
{
//....
}
|
... in the exact same order we included them. b.h and then a.h.
When you have a.h and a.cpp(which holds the definitions for the things declared in a.h) then a.h and a.cpp make a
translation unit and it will result in an a.obj on disk which will be later used when linking. This is done by compilers for optimization. Let's say you have 20 translation units in a project (a.h a.cpp, b.h b.cpp, c.h c.cpp and so on) and you use all those in main.cpp. You build once and objects are created: a.obj, b.obj, c.obj etc. Then you modify for example c.cpp. When you build again, only the c translation unit will be re-built into c.obj and also main.obj because it uses things from c (and any other unit which uses c) and that's it. The other units are already in .obj files and are used as they are at linking. So no need to rebuild all 20 units but just 2 (c and main).
PS: .obj is the naming done by Visual C++, other compilers name them differently (gcc objects are .o, and so on).
Regards,