OOP - Linking implementation and header

Hi guys,

I started the OOP chapter yesterday, and I get most of what is happening. However, there's one thing that's not really explained that I really do not get.

What I see them do is create 3 files, a header.h, a implementation.cpp and a main file.

As following:

1
2
3
4
5
6
7
//headerFile.h
#ifndef HEADERFILE_H
#define HEADERFILE_H

//class definition

#endif 


1
2
3
4
//Header implementation CPP file
#include "headerFile.h"

//methods 


1
2
3
4
5
6
7
8
//main CPP file
#include "headerFile.h"

int main () 
{
  // code
}


Now for my question, how does the main file reach the implementation? There is no include towards it, It includes the header file, but the header does not include the cpp file. I tested it, and executed it, and it works, but it baffles me how?

I can only assume that the implementation file is linked by the compiler to the header file somehow behind the scene, as there definitely is no code linking them.
Last edited on
that is the task of the linker.. your code gets compiled... and it compiles main and the header and it compiles the implementation and the header file...

The linker 'sees' you are using the definitions defined in the header in your main loop... and linkes them to the implementation in the in the implementation cpp file...
Last edited on
Alright, thanks a lot for the information :)
I'm glad to hear I didn't magically forget something somewhere.

Cheers
Topic archived. No new replies allowed.