PPaste!

Problème "undefined reference"

Home - All the pastes - Authored by Thooms

Raw version

  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
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
Personnage.h
#ifndef DEF_PERSONNAGE
#define DEF_PERSONNAGE

#include <iostream>
#include <string>

class Personnage

{

    public:

        Personnage();

        Personnage(std::string nom);

        void recevoirDegats(int degats);

        void coupDePoing(Personnage &cible) const;

        void sePresenter() const;



    protected:

        int m_vie;

        std::string m_nom;

};
#endif

Personnage.cpp
#include "Personnage.h"
#include <iostream>
#include <string>


using namespace std;

Personnage::Personnage() : m_vie(100), m_nom("Jack")
{

}

Personnage::Personnage(string nom) : m_vie(100), m_nom(nom)

{

}

void Personnage::recevoirDegats(int degats)

{

    m_vie -= degats;

}


void Personnage::coupDePoing(Personnage &cible) const

{

    cible.recevoirDegats(10);

}

void Personnage::sePresenter() const
{
  cout << "Bonjour mon nom est " << m_nom << "." << endl;
  cout << "J'ai " << m_vie << " points de vie." << endl;
}


int main()
{
  Personnage Marcel;
  Marcel.sePresenter();
  Guerrier lancelot("Lancelot du Lac")
  lancelot.sePresenter();

  return 0;
}

Guerrier.h
#ifndef DEF_GUERRIER
#define DEF_GUERRIER

#include <iostream>
#include <string>
#include "Personnage.h"

class Guerrier : public Personnage

{

public:

    Guerrier(std::string nom);
    void FrapperFort(Personnage &cible) const;

};

#endif

Guerrier.cpp
#include "Guerrier.h"
#include <iostream>
#include <string>

using namespace std;

Guerrier::Guerrier(string nom) : Personnage(nom)
{

}

void Guerrier::FrapperFort(Personnage &cible) const

{
    cible.recevoirDegats(20);
}


int main()
{
  Personnage Marcel;
  Marcel.sePresenter();
  //Guerrier Marcel("Lancelot du Lac");

  return 0;
}

message d'erreur:
/tmp/cczCYTXs.o: In function `Guerrier::Guerrier(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
Guerrier.cpp:(.text+0x42): undefined reference to `Personnage::Personnage(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/tmp/cczCYTXs.o: In function `Guerrier::FrapperFort(Personnage&) const':
Guerrier.cpp:(.text+0xa7): undefined reference to `Personnage::recevoirDegats(int)'
/tmp/cczCYTXs.o: In function `main':
Guerrier.cpp:(.text+0xce): undefined reference to `Personnage::Personnage()'
Guerrier.cpp:(.text+0xda): undefined reference to `Personnage::sePresenter() const'
collect2: error: ld returned 1 exit status