Becase I’ve seen (and used) situations like this:
In header.h:
class point
{
public:
point(xpos, ypos);
int x;
int y;
};
In def.cpp:
#include"header.h"
point::point(xpos, ypos)
{
x = xpos;
y = ypos;
}
In main.cpp:
#include"header.h"
int main()
{
point p1(5,6);
return 0;
}
I know the program executes from main, but how does the compiler know what order to compile .cpp files? (Particularily if there are more than one non-main .cpp files).
The compiler doesn’t care – it compiles each .cpp file into .obj file, and the .obj files each contain a list of missing symbols. So in this case, main.obj says “I’m missing
point::point“.It’s then the linker‘s job to take all the .obj files, combine them together into an executable, and make sure that each .obj file’s missing symbols are available from one of the other .obj files – hence the term “linker”.