Compilation of a header file in c++

  • Context: C/C++ 
  • Thread starter Thread starter krishna mohan
  • Start date Start date
  • Tags Tags
    C++ File
Click For Summary

Discussion Overview

The discussion revolves around the compilation process of header files in C++, specifically whether header files need to be compiled separately or if they are included and compiled with the main program.

Discussion Character

  • Conceptual clarification

Main Points Raised

  • One participant inquires about the necessity of separately compiling a header file when included in a main program using the #include directive.
  • Another participant asserts that the #include directive effectively copies the text of the header file into the .cpp file before it is passed to the compiler, implying that separate compilation is not needed.
  • A third participant seeks confirmation that the assertion means header files do not require separate compilation and are compiled with the main program.
  • A final participant expresses understanding of the explanation provided.

Areas of Agreement / Disagreement

Participants appear to agree that header files do not need to be compiled separately and are included in the compilation of the main program, though this is based on the interpretation of the responses rather than an explicit consensus.

krishna mohan
Messages
114
Reaction score
0
Hi..am just learning c++...i have a doubt..

Suppose you have a header file and you include it in your main program by using the #include directive..then do you have to compile the header file separately? Or does it get compiled with the main program?
 
Technology news on Phys.org
krishna mohan said:
Or does it get compiled with the main program?
Yes, all the #include does is copy the text of the header file into the .cpp file before passing it to the compiler
 
I guess your yes means that one does not have to compile a header file separately...and it gets compiled with the main program..?
 
I understand..thank you..
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
Replies
4
Views
5K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
81
Views
8K
  • · Replies 0 ·
Replies
0
Views
3K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 29 ·
Replies
29
Views
4K
Replies
6
Views
2K