Bonjour,
Je suis nouveau ici et je viens requerir de l'aide.
Voilà je sais que mon problème tourne autour de la définition d'objet static, mais cela fait maintenant 2h que je cherche sans succès une réponse.

voici mon fichier EtatRobot.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
#ifndef _ETATROBOT_H_
#define _ETATROBOT_H_
 
#include <string>
#include <map>
#include "Robot.h"
 
using namespace std;
 
class Robot;
 
class EtatRobot {
    public:
        EtatRobot(string nomEtat): _nomEtat(nomEtat){}
        virtual void avancer(int x,int y){throw BadStateException();}
        virtual void tourner(string direction){throw BadStateException();}
        virtual void saisir(Objet o){throw BadStateException();}
        virtual void poser(){throw BadStateException();}
        virtual int peser(){throw BadStateException();}
        virtual void rencontrerObstacle(Obstacle o){throw BadStateException();}
        virtual int evaluerObstacle(){throw BadStateException();}
        virtual void figer(){throw BadStateException();}
        virtual void repartir(){throw BadStateException();}
        string getNomEtat(){ return _nomEtat;}
        Robot* getRobot(){ return _robot;}
 
        static map<string,EtatRobot*> _mapEtats; 
 
        class BadStateException{};
 
    protected:
        /* data */
        string _nomEtat;
        Robot* _robot;
 
}; /* EtatRobot */
 
#endif /* end of include guard: _ETATROBOT_H_ */
Ici le .cpp
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
#include "EtatRobot.h"
#include "EtatAVide.h"
#include "EtatAVideFaceObstacle.h"
#include "EtatEnCharge.h"
#include "EtatEnChargeFaceObstacle.h"
#include "EtatFige.h"
#include "Robot.h"
 
 
map<string,EtatRobot*> EtatRobot::_mapEtats;
EtatAVide EtatAVide::eav("VIDE");
EtatAVideFaceObstacle EtatAVideFaceObstacle::eavfo("AVIDEOBS");
EtatEnCharge EtatEnCharge::eec("ENCHARGE");
EtatEnChargeFaceObstacle EtatEnChargeFaceObstacle::eecfo("ENCHARGEOBS");
EtatFige EtatFige::ef("FIGE");
Et après j'ai des états qui dérive de EtatRobot avec une variable static style eav pour EtatAVide.

Les erreurs sont :
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
EtatRobot.o:(.bss+0x0): multiple definition of `EtatRobot::_mapEtats'
EtatRobot.o:(.bss+0x0): first defined here
EtatRobot.o:(.bss+0x30): multiple definition of `EtatAVide::eav'
EtatRobot.o:(.bss+0x30): first defined here
EtatRobot.o:(.bss+0x50): multiple definition of `EtatAVideFaceObstacle::eavfo'
EtatRobot.o:(.bss+0x50): first defined here
EtatRobot.o:(.bss+0x70): multiple definition of `EtatEnCharge::eec'
EtatRobot.o:(.bss+0x70): first defined here
EtatRobot.o:(.bss+0x90): multiple definition of `EtatEnChargeFaceObstacle::eecfo'
EtatRobot.o:(.bss+0x90): first defined here
EtatRobot.o:(.bss+0xc0): multiple definition of `EtatFige::ef'
EtatRobot.o:(.bss+0xc0): first defined here
main.o: In function `main':
main.cpp:(.text+0x18): undefined reference to `Robot::Robot()'
EtatRobot.o: In function `EtatFige::repartir()':
EtatRobot.cpp:(.text._ZN8EtatFige8repartirEv[EtatFige::repartir()]+0x23): undefined reference to `Robot::changeEtat(EtatRobot*)'
EtatEnRoute.o: In function `EtatEnRoute::figer()':
EtatEnRoute.cpp:(.text+0xad): undefined reference to `Robot::changeEtat(EtatRobot*)'
EtatEnCharge.o: In function `EtatEnCharge::rencontrerObstacle(Obstacle&)':
EtatEnCharge.cpp:(.text+0x23): undefined reference to `Robot::changeObs(Obstacle)'
EtatEnCharge.cpp:(.text+0x6b): undefined reference to `Robot::changeEtat(EtatRobot*)'
EtatEnCharge.o: In function `EtatEnCharge::peser()':
EtatEnCharge.cpp:(.text+0xd2): undefined reference to `Robot::getObjet()'
EtatEnCharge.o: In function `EtatEnCharge::avancer(int, int)':
EtatEnCharge.cpp:(.text+0x10e): undefined reference to `Robot::changePos(int, int)'
EtatEnCharge.o: In function `EtatEnCharge::tourner(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
EtatEnCharge.cpp:(.text+0x14b): undefined reference to `Robot::changeDir(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
EtatEnChargeFaceObstacle.o: In function `EtatEnChargeFaceObstacle::poser()':
EtatEnChargeFaceObstacle.cpp:(.text+0x37): undefined reference to `Robot::changeObj(Objet)'
EtatEnChargeFaceObstacle.cpp:(.text+0x7f): undefined reference to `Robot::changeEtat(EtatRobot*)'
EtatEnChargeFaceObstacle.o: In function `EtatEnChargeFaceObstacle::peser()':
EtatEnChargeFaceObstacle.cpp:(.text+0xfe): undefined reference to `Robot::getObjet()'
EtatEnChargeFaceObstacle.o: In function `EtatEnChargeFaceObstacle::tourner(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
EtatEnChargeFaceObstacle.cpp:(.text+0x14b): undefined reference to `Robot::changeDir(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
EtatEnChargeFaceObstacle.cpp:(.text+0x19f): undefined reference to `Robot::changeEtat(EtatRobot*)'
EtatAVide.o: In function `EtatAVide::rencontrerObstacle(Obstacle&)':
EtatAVide.cpp:(.text+0x23): undefined reference to `Robot::changeObs(Obstacle)'
EtatAVide.cpp:(.text+0x6b): undefined reference to `Robot::changeEtat(EtatRobot*)'
EtatAVide.o: In function `EtatAVide::tourner(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
EtatAVide.cpp:(.text+0xf1): undefined reference to `Robot::changeDir(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
EtatAVide.o: In function `EtatAVide::avancer(int, int)':
EtatAVide.cpp:(.text+0x148): undefined reference to `Robot::changePos(int, int)'
EtatAVideFaceObstacle.o: In function `EtatAVideFaceObstacle::evaluerObstacle()':
EtatAVideFaceObstacle.cpp:(.text+0x18): undefined reference to `Robot::getObstacle()'
EtatAVideFaceObstacle.o: In function `EtatAVideFaceObstacle::tourner(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
EtatAVideFaceObstacle.cpp:(.text+0x65): undefined reference to `Robot::changeDir(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
EtatAVideFaceObstacle.cpp:(.text+0xb9): undefined reference to `Robot::changeEtat(EtatRobot*)'
EtatAVideFaceObstacle.o: In function `EtatAVideFaceObstacle::saisir(Objet&)':
EtatAVideFaceObstacle.cpp:(.text+0x145): undefined reference to `Robot::changeObj(Objet)'
EtatAVideFaceObstacle.cpp:(.text+0x18d): undefined reference to `Robot::changeEtat(EtatRobot*)'
collect2: ld a retourné 1 code d'état d'exécution
make: *** [main] Erreur 1
Merci beaucoup pour votre aider.