Bonjour,

Je suis débutant en c++ et je travailles avec les classes. J'ai eu une erreure grave. À chaque fois que j'execute le code. Il y a une alerte qui dit : violation d'acces lors de l'ouverture. Comment est-ce possible?

wizard.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
#ifndef WIZARD_H
#define WIZARD_H
#include <iostream>
#include "latale.h"
 
class wizard : public Personnage
{
public:
	void sorc();
};
#endif
warrior.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
#ifndef WARRIOR_H
#define WARRIOR_H
#include <iostream>
#include "latale.h"
 
class warrior : public Personnage
{
public:
	void bankai();
};
 
#endif
latale.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
#ifndef LATALE_H
#define LATALE_H
#include <iostream>
#include <string>
#include "arme.h"
#include "armure.h"
 
class Personnage
{
private:
	int hp;
	int sp;
	int xp;
	int level;
	double argent;
	std::string nom;
	std::string classe;
	bool estVivant;
	int force;
	int rapidite;
	int defense;
	Arme *m_arme;
	armure *m_armure;
 
public:
	Personnage();
	int getForce() const;
	int getRapidite() const;
	void frapper(Personnage &cible);
	int getDefense() const;
	bool getVivant() const;
	void faireFrapper(int arg1);
	int getHp() const;
	int getSp() const;
	void execution();
};
#endif
head.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
#include <iostream>
#include <string>
#include "latale.h"
#include "warrior.h"
#include "wizard.h"
 
Personnage::Personnage()
{
	nom = "Ben";
	hp = 100;
	sp = 100;
	xp = 0;
	level = 0;
	estVivant = true;
}
 
int Arme::getPuissance() const
{
	return puissance;
}
 
int Personnage::getForce() const
{
	int vitesse = getRapidite()/100;
	return force+m_arme->getPuissance()+vitesse;
}
 
int Arme::getLeger() const
{
	return leger;
}
 
int armure::getProtection() const
{
	return protection;
}
 
int armure::getLourd() const
{
	return lourd;
}
 
int Personnage::getDefense() const
{
	return defense*m_armure->getProtection();
}
 
int Personnage::getRapidite() const
{
	return rapidite+m_arme->getLeger()-m_armure->getLourd();
}
 
 
armure::armure(string arg1,int arg2,int arg3)
{
	nom_armure = arg1;
	protection = arg2;
	lourd = arg3;
}
 
Arme::Arme(std::string arg1,int arg2, int arg3, int arg4)
{
	nom_arme = arg1;
	puissance = arg2;
	leger = arg3;
	level_min = arg4;
}
 
bool Personnage::getVivant() const
{
	return estVivant;
}
 
int Personnage::getHp() const
{
	return hp;
}
 
int Personnage::getSp() const
{
	return sp;
}
 
void Personnage::faireFrapper(int arg1)
{
	if(hp > 0)
	{
		hp -= arg1;
	}
}
 
void Personnage::execution()
{
	estVivant = false;
}
 
void Personnage::frapper(Personnage &cible)
{
	if(sp >= 5 && estVivant == true && cible.getVivant() == true)
	{
		int dommage = cible.getDefense()-getForce();
		cible.faireFrapper(dommage);
		if(cible.getHp() < 0)
		{
			execution();
		}
	}
}
arme.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#ifndef ARME_H
#define ARME_H
#include <iostream>
#include <string>
 
class Arme
{
private:
	std::string nom_arme;
	int puissance;
	int leger;
	int level_min;
public:
	Arme(std::string arg1,int arg2, int arg3, int arg4);
	int getPuissance() const;
	int getLeger() const;
};
#endif
armure.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#ifndef ARMURE_H
#define ARMURE_H
#include <iostream>
#include <string>
using namespace std;
 
class armure
{
private:
	std::string nom_armure;
	int protection;
	int lourd;
public:
	armure(std::string arg1,int arg2,int arg3);
	int getProtection() const;
	int getLourd() const;
};
 
#endif
trainning.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <string>
#include "head.h"
 
using namespace std;
 
int main()
{
	warrior ben;
	wizard sam;
	ben.frapper(sam);
	return 0;
}