Bonjours à tous et à toutes,
Je suis nouveau sur le site, donc en cas d'erreur avec ce post, merci de me le faire savoir :)
Pour en venir au problème, j'essaye de faire une classe qui hérite d'une autre classe.
Classe Mère : Player
Classe Fille : Tank
player.h :
player.cpp :Code:
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 #ifndef PLAYER_H_INCLUDED #define PLAYER_H_INCLUDED #include <iostream> #include "arme.h" class Player { public: Player(int vie, int mana, std::string name, std::string a_name, int a_degats); ~Player(); void afficher() const; void recevoirDegats(int degats); void attaquer(Player &cible); bool estVivant() const; private: int m_vie, m_mana; std::string m_name; bool m_vivant; Arme *m_arme; }; #endif // PLAYER_H_INCLUDED
tank.h :Code:
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 #include <iostream> #include "player.h" #include "arme.h" using namespace std; Player::Player(int vie, int mana, std::string name, std::string a_name, int a_degats) : m_vie(vie), m_mana(mana), m_name(name) { m_arme = new Arme(a_name, a_degats); } Player::~Player() { delete m_arme; } void Player::afficher() const { cout << "Pseudo : " << m_name << endl; cout << "Vie : " << m_vie << endl; cout << "Mana : " << m_mana << endl; cout << "Arme : " << m_arme->getNameArme() << endl; } void Player::recevoirDegats(int degats) { m_vie -= degats; if(m_vie <= 0) { m_vie = 0; m_vivant = false; } } bool Player::estVivant() const { return m_vivant; } void Player::attaquer(Player &cible) { cible.recevoirDegats(m_arme->getDegats()); }
tank.cppCode:
1
2
3
4
5
6
7
8
9
10
11
12
13 #ifndef TANK_H_INCLUDED #define TANK_H_INCLUDED #include "player.h" #include "arme.h" class Tank : public Player { public: }; #endif // TANK_H_INCLUDED
Bah voila le problème j'ai rien mis dedans, comme je veux que tank hérite tout de Player ^^
Dans mon fichier main.cpp :
Et voici l'erreur généré par mon compilateur :Code:
1
2
3 Player player(500, 100, pseudo, "Vieux couteau", 15); Tank tank(1000, 150, "ogre", "Marteau", 5);
Merci d'avance de votre aide, je cherche de mon côté ! :)Code:error: no matching function for call to 'Tank::Tank(int, int, const char [5], const char [8], int)'
PS: je ne suis pas un expert du c++, et je cherche juste à apprendre ^^