Bug : Méthode

Résolu
TheYoungGeek43 Messages postés 112 Statut Membre -  
TheYoungGeek43 Messages postés 112 Statut Membre -
Bonjour,

Je regarde le site du zero pour apprendre le C++ et dans leur cours il apprenne a faire les classe les méthode ect... et moi j'ai un bug

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

using namespace std;

int main()
{
	
	// Création des personnages
	Personnage david, goliath("Epée aiguisée", 20);

	// Au combat !
	goliath.attaquer(david);
	david.boirePotionDeVie(20);
	goliath.attaquer(david);
	david.attaquer(goliath);
	goliath.changerArme("Double hache tranchante vénéneuse de la mort", 40);
	goliath.attaquer(david);

	// Temps mort ! Voyons voir la vie de chacun...
	cout << "David" << endl;
	david.afficherEtat();
	cout << endl << "Goliath" << endl;
	goliath.afficherEtat();

	system("PAUSE");
	return 0;
}

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

using namespace std;

Personnage::Personnage():m_vie(100), m_mana(100)
{}
Personnage::Personnage(string nomArme, int degatsArme) :m_vie(100), m_mana(100), m_arme(nomArme,degatsArme)
{}
Personnage::Personnage(int vie, int mana):m_vie(100), m_mana(100)
{}
void Personnage::recevoirDegats(int nbDegats)
{

	m_vie -= nbDegats;

	if (m_vie < 0)
	{
			m_vie = 0;
	}

}
void Personnage::attaquer(Personnage &cible)
{

	cible.recevoirDegats(m_arme.getDegats());

}
void Personnage::boirePotionDeVie(int quantitePotion)
{
	m_vie += quantitePotion;

	if (m_vie > 100)
	{
		m_vie = 100;
	}
}
void Personnage::changerArme(string nomNouvelleArme, int degatsNouvelleArme)
{
	m_arme.changer(nomNouvelleArme, degatsNouvelleArme);
}
bool Personnage::estVivant() const 
{
		
	if (m_vie > 0)
	{
		return true;
	}
	else
	{
		return false;
	}

}
void Personnage::afficherEtat() const
{
	cout << "Vie : " << m_vie << endl;
	cout << "Mana : " << m_mana << endl;
	m_arme.affiche();
}
Personnage::~Personnage()
{

}

Personnage.h
#ifndef DEF_PERSONNAGE
#define DEF_PERSONNAGE

#include <string>
#include "Arme.h"

class Personnage
{
	public:

	Personnage(std::string nomArme, int degatsArme); // Constructeur
	Personnage();
	Personnage(int vie, int mana);
	void recevoirDegats(int nbDegats);
	void attaquer(Personnage &cible);
	void boirePotionDeVie(int quantitePotion);
	void changerArme(string nomNouvelleArme, int degatsNouvelleArme);
	bool estVivant() const;
	void afficherEtat() const;
	~Personnage();

	private:

	int m_vie;
	int m_mana;
	Arme m_arme;
};

#endif // !DEF_PERSONNAGE

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

using namespace std;

Arme::Arme():m_nom("Epée rouillée"), m_degats(10)
{}
Arme::Arme(string nom, int degats):m_nom(nom),  m_degats(degats)
{}
void Arme::changer(string nom, int degats)
{
	m_nom = nom;
	m_degats = degats;
}  
void Arme::afficher()
{
	cout << "Arme : " << m_nom << " (Dégâts : " << m_degats << ")" << endl;
}
int Arme::getDegats() const
{
	return m_degats;
}

Arme.h
#ifndef DEF_ARME
#define DEF_ARME

#include <iostream>
#include <string>

class Arme
{
public:
	Arme();
	Arme(std::string nom, int degats);
	void changer(std::string nom, int degats);
	void afficher();
	int getDegats() const;

private:
	std::string m_nom;
	int m_degats;

};


#endif // !DEF_ARME

Mon compilateur me dit que dans le main la ligne 19 qui est "goliath.changerArme("Double hache tranchante vénéneuse de la mort", 40);" ne devrait pas avoir 2 argument et je ne comprend pas pourquoi il me dit ça


Merci de vos réponses

1 réponse

JwTdd
 
Salut, tu as mis string nomNouvelleArme au lieu de std::string nomNouvelleArme dans personnage.h
0
TheYoungGeek43 Messages postés 112 Statut Membre
 
Salut effectivement j'ai pas totalement l'oeil ;)
0
TheYoungGeek43 Messages postés 112 Statut Membre
 
Maintenant j'ai un gros problème ces que mes include ne sont pas accepter par le compilateur
J'ai mis les même include dans toute mes classe
#include <iostream>
#include <string>


Mon compilateur me dit
Gravité	Description	Projet	Fichier	Ligne
Erreur	IntelliSense : impossible d'ouvrir le fichier source "iostream"	Pratique	Arme.h	4
Erreur	IntelliSense : impossible d'ouvrir le fichier source "string"	Pratique	Arme.h	5
Erreur	IntelliSense : impossible d'ouvrir le fichier source "iostream"	Pratique	Main.cpp	1
Erreur	IntelliSense : impossible d'ouvrir le fichier source "string"	Pratique	Main.cpp	2

donc ça fait bug tous mon programme (les cout, les string, les endl ect...)
0