Class initializer problem

Hello Everybody . I'm new to the C++ community and environment too.
Anyway , I was trying to code a tiny portion of a RPG game in console and the problem comes with my Character Class.
The compiler refuse to compile because of that error: undefined reference to 'Character::Character()'

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//Main.cpp

#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <time.h>
#include "Character.h"


using namespace std;


int main()
{
    srand(time(0));
    Character junior, frank;
    return 0;
}

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
48
49
50
51
52
53
54
55
56



//Character.cpp

#include "Character.h"


using namespace std;

Character::Character()
{
    m_vie = 100;
    m_mana = 100;
}

    void Character::showlife ()
    {

    }

    void Character:: getdmg (int m_vie)
    {
       m_vie -= 10;
    }

    void Character::attack (Character &target)
    {

    }

    void Character::healing (int m_vie)
    {
      m_vie += 20;
    }

    void Character::manaregen (int m_mana)
    {

    }

    void Character::expgain (int m_exp)
    {

    }

    void Character::levelup (int m_level)
    {

    }

    bool Character::die (bool m_alive)
    {

    }

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
//Character.h


#ifdef DEF_CHARACTER
#define DEF_CHARACTER
#endif // DEF_CHARACTER



class Character{

public:
Character();

    void showlife (int m_vie);
    void getdmg (int m_vie);
    void attack (Character &target);
    void healing (int m_vie);
    void manaregen (int m_mana);
    void expgain (int m_exp);
    void levelup (int m_level);
    bool die (bool m_alive);

private:

int m_vie = 100;
int m_mana = 100;
int m_exp = 0;
int m_level = 1;
bool m_alive = true;
};
Have you added Character.cpp to your compile line or project?
Yeah, I use Codeblock and main.cpp , Character.cpp and Character.h are linked together in the same project
Topic archived. No new replies allowed.