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.
The command:
g++ -o main main.cpp add.cpp -Wall
Works fine. However, that confuses me about the point of the header file. At the moment, I have the simple program:
#include <iostream>
#include "add.h"
using namespace std;
int main () {
int a, b;
cout << "Enter two numbers to add together" << endl;
cin >> a >> b;
cout << "Sum of " << a << " and " << b << " is " << add(a,b) << endl;
return 0;
}
Where my "add.cpp" is simply adding the two numbers together.
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.