Depuis quelque jour je code un petit jeu pour améliorer mes connaissances en programmation.
J'ai une classe TPersonnage qui jusqu'a vendredi ne posais pas de problème et depuis hier impossible de compiler mon projet à cause de cette erreur :
Code:
1
2
3
4
5
6
7 E:\Mes documents\Texte\tpopulation.h:17: error: ISO C++ forbids declaration of `TPersonnage' with no type E:\Mes documents\Texte\tpopulation.h:17: error: expected `;' before '*' token E:\Mes documents\Texte\tpopulation.h:21: error: `TPersonnage' was not declared in this scope E:\Mes documents\Texte\tpopulation.h:21: error: template argument 1 is invalid E:\Mes documents\Texte\tpopulation.h:21: error: template argument 2 is invalid E:\Mes documents\Texte\tpopulation.h:21: error: ISO C++ forbids declaration of `peuple' with no type :: === Build finished: 6 errors, 0 warnings ===
Je pense que ca vient d'une erreur de syntaxe mais je n'arrive pas à la retrouver.
voici le code où ca bloque :
extrait deCode:
1
2 TPersonnage* Get(int id);
le fichier.cpp correspondantCode:
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 #ifndef TPOPULATION_H #define TPOPULATION_H #include <vector> #include "tpersonnage.h" #include <string> #include "TBiblio.h" class TPopulation { public: TPopulation(); void Add(int id, std::string nom , int texture,double direction,double x, double y); void LoadFromFile(std::string source); void Draw(TBiblio *biblio); TPersonnage* Get(int id); ~TPopulation(); protected: private: std::vector <TPersonnage> peuple; }; #endif // TPOPULATION_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
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 #include "tpopulation.h" #include "tpersonnage.h" #include <vector> #include "TBiblio.h" #include <fstream> using namespace std; TPopulation::TPopulation() { //ctor } void TPopulation::Add(int id, std::string nom , int texture,double direction,double x, double y) { TPersonnage personne(id, nom, texture,direction,x,y); peuple.push_back(personne); } void TPopulation::Draw(TBiblio *biblio) { for (unsigned int i=0; i<peuple.size();i++) { TPersonnage land=peuple[i]; land.Draw(biblio); } } void TPopulation::LoadFromFile(std::string source) { ifstream f(source.c_str()); int n; int id; string nom; int texture; double x; double y; double direction; f>>n; for (int i=0;i<n;i++) { f>>id; f>>nom; f>> texture; f>> direction; f>> x; f>> y; Add(id,nom,texture,direction,x,y); } f.close(); } TPersonnage* TPopulation::Get(int id) { TPersonnage* personne= &peuple[id]; return personne; } TPopulation::~TPopulation() { //dtor }
et voici ma classe :
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
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 #include "tpersonnage.h" #include <string> #include "TBiblio.h" #include <math.h> #include "constantes.h" #include "tmap.h" #include "tterrain.h" #include <iostream> using namespace std; TPersonnage::TPersonnage() { //ctor } TPersonnage::TPersonnage(int id, std::string nam , int texture,double direction,double x, double y) { this->id=id; this->texture=texture; this->nom= nam; this->direction=direction; this->position.x=x; this->position.y=y; //ctor } void TPersonnage::Draw(TBiblio *biblio) { glTranslated(position.x,position.y,0); glRotated(direction,0,0,1); glBindTexture(GL_TEXTURE_2D, biblio->Get(texture)); glBegin(GL_QUADS); glTexCoord2i(0,0); glVertex2d(-16,-16); glTexCoord2i(1,0); glVertex2d(16,-16); glTexCoord2i(1,1); glVertex2d(16,16); glTexCoord2i(0,1); glVertex2d(-16,16); glEnd(); glDisable(GL_TEXTURE_2D); glBegin(GL_LINES); glVertex2d(0,50); glVertex2d(0,0); glEnd(); glEnable(GL_TEXTURE_2D); glTranslated(-position.x,-position.y,0); glRotated(-direction,0,0,1); glLoadIdentity(); } void TPersonnage::Walk(Uint32 temps, double angle, TMap *carte) { TPosition lastPostion=position; double distance= temps*0.2; direction=angle; position.x+=cos(angle*PI/180)*distance; position.y+=sin(angle*PI/180)*distance; for (int i=0;i<carte->GetSize();i++) { TTerrain* terre= carte->Get(i); bool rep =terre->IsOnRect(&position); if (rep==true&& terre->GetTexture()==1) position=lastPostion; } } TPosition TPersonnage::GetPosition() { return position; } /*TPersonnage::~TPersonnage() { //dtor }*/
Je vous remercie d'avance pour l'aide que vous pourriez m'apporterCode:
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 #ifndef TPERSONNAGE_H #define TPERSONNAGE_H #include <string> #include "TBiblio.h" #include "tmap.h" #include "constantes.h" #include "tscene.h" class TPersonnage { public: TPersonnage(); TPersonnage(int id, std::string nam , int texture,double direction,double x, double y); void Draw(TBiblio *biblio); void Walk(Uint32 temps, double angle, TMap *carte); TPosition GetPosition(); //~TPersonnage(); protected: private: int id; std::string nom; int texture; double direction; TPosition position; //TAction action; }; #endif // TPERSONNAGE_H