header files and source files

hey guys, i have this assignment i know what to do but in the assignmnet the professor asks us to declare the method in mymath.h and define it in mymath.cpp and to use it in main.cpp. this is the part where i have NO idea what to do. the professor gives the assignment before explaining in class. he asks us to search for the things we dont know and i am in a bad situation. i am in terrible need of help. can you give me an explanation of what am i supposed to do? thanks for your help
If you were to make a single file called main.cpp and put this in it:
1
2
3
4
int main()
{
    return 0;
}

how do you compile and run it? Do you run it in an IDE or do you compile at the command line with g++ or something similar?
Last edited on
I think he's trying to teach you how to do separate compilation (multiple source files).

http://www.youtube.com/watch?v=IMuf781DAQc

This should help. If it isn't enough just search for "C++ working with multiple files" or something like that to find more tutorials.
mymath.h:
This is the same thing as doing a forward declaration in a single file.
int add(int a, int b);

mymath.cpp:
This is the implementation
1
2
3
4
5
#include "mymath.h"
int add(int a, int b)
{
    return a+b;
}


main.cpp
This is the usage
1
2
3
4
5
6
#include <iostream>
#include "mymath.h"
int main()
{
    std::cout << add(1, 2);
}


thanks guys :)
Topic archived. No new replies allowed.