Undefined reference??

Hi I'm slightly new with programming and I'm getting an undefined error.
I have a main.cpp source file, and soldier.h header file, and a soldier.cpp source file. I declared some functions in the header file and defined them in the soldier.cpp file. When I call them in main.cpp, they don't run and I get an error "undefined reference". When I know that I defined them! Here is the code for my header file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  #include <iostream>
using namespace std;


class Soldier
{
public:

    Soldier(int x, int y);
    void attack();
    void heal( int z);
    void beAttacked();
    int getHealth();

private:
    int health;
    int strength;
};

closed account (Dy7SLyTq)
im assuming you are using an ide. if so, you need to add the .cpp file to the project
I am using codeblocks.
I have 3 files.
main.cpp
soldier.h
soldier.cpp

trying to get the functions from soldier to main. the files are in the same project.
Last edited on
I have no idea what happened but I just recreated the files and pasted their code back in and it would work. What I noticed was the problem was the actual header file and soldier source file wouldn't build or tell you any errors. I fixed it. thanks.
Topic archived. No new replies allowed.