header file problems

Hello,
I know that you guys get sick of answering questions about multiple files in c++, and I am sure my problems are coming from not totally understanding what I am doing, but I need to figure out how to do this. Here is my code, which I wrote simply to try to get an understanding as to how headers work.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//in main.cpp

#include <iostream>
#include "sum.h"

using namespace std;



int main()
{
    int a = 0;
    int b = 0;

    cout << "Enter a number: " << endl;
    cin>> b;
    cout << "Enter a second number: " << endl;
    cin >> a;


    cout << "The sum is: " << add(a, b) << endl;

    return 0;
}


//in sum.h

#ifndef SUM_H_INCLUDED
#define SUM_H_INCLUDED

int add(int& argOne, int& argTwo);

#endif // SUM_H_INCLUDED


//in sum.cpp

#include "sum.h"

int add(int& argOne, int& argTwo)
{
    int sum = 0;
    sum = argOne + argTwo;
    return sum;
}


The error I am getting is:

obj/Debug/main.o||In function `main':|
undefined reference to `add(int&, int&)'|

I appreciate any help you all can give. Thank you.

Never mind, marking as solved. Next time I will set the linker up correctly....
Last edited on
Topic archived. No new replies allowed.