title: Compiling with g++ - including header files
body: <p>I just have a  quick question as I'm trying to understand how to compile (in ubuntu 12.04) a main in c++ that includes a simple header file. </p>
  
  <p>The command: </p>
  
  <pre><code>g++ -o main main.cpp add.cpp -Wall
  </code></pre>
  
  <p>Works fine. However, that confuses me about the point of the header file. At the moment, I have the simple program: </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "add.h"
  using namespace std;
  
  int main () {
  
  
    int a, b;
    cout &lt;&lt; "Enter two numbers to add together" &lt;&lt; endl;
    cin &gt;&gt; a &gt;&gt; b;
    cout &lt;&lt; "Sum of " &lt;&lt; a &lt;&lt; " and " &lt;&lt; b &lt;&lt; " is " &lt;&lt; add(a,b) &lt;&lt; endl;
  
    return 0;
  
  }
  </code></pre>
  
  <p>Where my "add.cpp" is simply adding the two numbers together. </p>
  
  <p>Is the header file simply a replacement for the function prototype? Do I need to compile the header file separately or is it sufficient to include all of the .cpp files in the command line? I understand that if I need more files a makefile would be necessary. </p>