Bonjour à tous !
Voila dans le cadre de l'un de mes projets (un jeu de Taquin), j'ai voulu créer une classe d'exception, s'occupant de gérer toutes les exceptions sur mon prog.
Suite à ça, je commence à créer une, puis deux, puis trois classes, et là c'est le drame ! Le compilo déconne sur le main avec le message suivant :
Le problème... C'est que j'ai mis les #ifndef, #define et #endif sur toutes mes classes !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 In file included from Watcher.h:4:0, from main.cpp:5: PuzzleException.h:13:7: error: redefinition of class PuzzleException PuzzleException.h:13:7: error: previous definition of class PuzzleException
J'avoue que là... Je suis paumé !
Voici ma classe d'exception :
(Excusez si c'est moche, mais c'est en cours d'écriture )
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 #ifndef PUZZLEEXCEPTION_H #define PUZZLEEXCEPTION_h #include <iostream> #include <sstream> #include <exception> /* Je vous passe les commentaires Doxygen . . */ class PuzzleException : public std::exception{ public : inline PuzzleException(int id=0, std::string const& message= "") throw() : $identification(id), $message(message){} inline virtual const char* what() const throw(){ std::ostringstream _oss; _oss << $identification; std::string _result = _oss.str(); _result += " : "; _result += $message; return (_result.c_str()); } inline virtual ~PuzzleException() throw(){} private: int $identification; std::string $message; }; #endif /* PUZZLEEXCEPTION_H */
Le header de ma classe Brick :
Celui de ma classe Watcher :
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 #ifndef BRICK_H #define BRICK_H #include "PuzzleException.h" class Brick{ public: Brick(int val); int getValue(); void setValue(int new_val); private: int $value; }; #endif /* BRICK_H */
Et enfin mon Main :
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 WATCHER_H #define WATCHER_H #include "PuzzleException.h" class Watcher{ public: Watcher(); int getNbMovePlayed(); int getNbRemainingMove(); void setNbRemainingMove(int val); void increaseMovePlayed(); private: int $move_played; int $remaining_move; }; #endif /* WATCHER_H */
Pareil, pardon aux familles si c'est moche, tout ça...
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 #include <iostream> #include "PuzzleException.h" #include "Movement.h" #include "Brick.h" #include "Watcher.h" int main(){ //Brick class test if(state == 0){ Brick br(32); try{ Brick br2(-42); state = 1; s = "Exception expected on Brick Construction"; } catch(PuzzleException &e){} if(br.getValue() != 32){state = 1; s="Bad Brick::getValue()";} br.setValue(42); if(br.getValue() != 42){state = 1; s="Bad Brick::setValue()";} } //Watcher class test if(state == 0){ Watcher wa; if(wa.getNbMovePlayed() != 0){state =1 ; s="Bad Watcher::getNbMovePlayed()";} for (int _i = 0 ; _i < 10 ; _i++){wa.increaseMovePlayed();} if(wa.getNbMovePlayed() != 10){state = 1; s="Bad Watcher::increaseNbMovePlayed()";} if(wa.getNbRemainingMove() != 0){state = 1; s="Bad Watcher::getRemainingMove()";} wa.setNbRemainingMove(42); if(wa.getNbRemainingMove() != 42){state = 1; s="Bad Watcher::setRemainingMove()";} try{ wa.setNbRemainingMove(-42); state = 1; s = "Expect exception on Watcher::setRemainingMove()"; }catch(PuzzleException &e){} } //Result std::cout << s << std::endl; return state; }
Bref, Quelqu'un a-t-il une idée ?
Walther Bishop
PS : Etant nouveau posteur sur le forum, désolé si je me suis trompé de topic
Partager