Bonjour,
J'ai un probleme de compilation sous VC.
Voici le code :
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 // geometric_shape_factory.hpp #ifndef __GEOMETRIC_SHAPE_FACTORY_HPP__ #define __GEOMETRIC_SHAPE_FACTORY_HPP__ #include <map> #include <string> #include "geometric_shape.hpp" template <typename KEY , class OBJECT> class GeometricShapeFactory { public: // un pointeur de fonction qui retourne un Object* typedef OBJECT *(*Creator)(void); // Le map qui stocke les associations entre la cle et le pointeur de fonction std::map<KEY, Creator> _registeredCreator; static bool Register(KEY key, Creator creator) { if( _registeredCreator.find(key) != _registeredCreator.end() ) return false; // la clef est deja utilisé _registeredCreator.insert(std::pair<KEY, Creator>(key, creator) ); return true; } OBJECT * Create(KEY key) { OBJECT *object; Creator creator; std::map<KEY, Creator>::iterator it; // On cherche le pointeur de fonction associé a la clef it = _registeredCreator.find(key); if( it == _registeredCreator.end() ) return NULL; // on ne l'a pas trouvé // On récupère le pointeur de fonction creator = (*it).second; // On appelle la fonction pour créer un nouvel objet object = (*creator)(); // On retourne l'objet return object; } }; #endif
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 // square_shape.hpp #ifndef __SQUARE_SHAPE_HPP__ #define __SQUARE_SHAPE_HPP__ #include "geometric_shape.hpp" #include <vector> #include <iostream> /** @brief @author OTO @date **/ class SquareShape : public GeometricShape { public: /// \brief Création d'un objet SquareShape static GeometricShape* create( void ); /// Set / Modification des paramètres d'un objet SquareShape /// @param param Le vecteur contenant les paramètres de l'objet SquareShape void SetParameters( const std::vector<double> & param ); /// Permet de connaître l'état du flag _is_registered bool IsRegistered() {std::cout << "registered = " << _is_registered;return _is_registered;}; private: /// Flag indiquant si l'objet SquareShape est enregistré dans la <i>Factory</i> GeometricShapeFactory static bool _is_registered; double _size; }; /** * @todo Finir l'implémentation de la classe ... **/ #endifEt j'ai les erreurs suivantes a la compilation (j'ai volontairement omis de mettre le code de la classe rectangle_shape qui est similaire a celui de la classe square_shape ...) :
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 // square_shape.cpp #include "../include/square_shape.hpp" #include "../include/geometric_shape_factory.hpp" #include <iostream> #include <string> #include <algorithm> GeometricShape * SquareShape::create(void) { return new SquareShape(); } void SquareShape::SetParameters( const std::vector<double> & param ) { ; } bool SquareShape::_is_registered = GeometricShapeFactory<std::string,GeometricShape>::Register("SquareShape", SquareShape::create);
Je ne comprends absolument pas pourquoi ... Une idee ?
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 Compilation... square_shape.cpp e:\Developpement\pimplib\pimplib_geometric_objects\src\../include\geometric_shape_factory.hpp(19) : error C2228: la partie gauche de '.find' doit avoir un type class/struct/union le type est '' e:\Developpement\pimplib\pimplib_geometric_objects\src\../include\geometric_shape_factory.hpp(18) : lors de la compilation de la fonction membre du modèle de classe 'bool GeometricShapeFactory<KEY,OBJECT>::Register(KEY,GeometricShapeFactory<KEY,OBJECT>::Creator)' with [ KEY=std::string, OBJECT=GeometricShape ] src\square_shape.cpp(18) : voir la référence à l'instanciation du modèle de classe 'GeometricShapeFactory<KEY,OBJECT>' en cours de compilation with [ KEY=std::string, OBJECT=GeometricShape ] e:\Developpement\pimplib\pimplib_geometric_objects\src\../include\geometric_shape_factory.hpp(19) : error C2228: la partie gauche de '.end' doit avoir un type class/struct/union le type est '' e:\Developpement\pimplib\pimplib_geometric_objects\src\../include\geometric_shape_factory.hpp(21) : error C2228: la partie gauche de '.insert' doit avoir un type class/struct/union le type est '' rectangle_shape.cpp e:\Developpement\pimplib\pimplib_geometric_objects\src\../include\geometric_shape_factory.hpp(19) : error C2228: la partie gauche de '.find' doit avoir un type class/struct/union le type est '' e:\Developpement\pimplib\pimplib_geometric_objects\src\../include\geometric_shape_factory.hpp(18) : lors de la compilation de la fonction membre du modèle de classe 'bool GeometricShapeFactory<KEY,OBJECT>::Register(KEY,GeometricShapeFactory<KEY,OBJECT>::Creator)' with [ KEY=std::string, OBJECT=GeometricShape ] src\rectangle_shape.cpp(14) : voir la référence à l'instanciation du modèle de classe 'GeometricShapeFactory<KEY,OBJECT>' en cours de compilation with [ KEY=std::string, OBJECT=GeometricShape ] e:\Developpement\pimplib\pimplib_geometric_objects\src\../include\geometric_shape_factory.hpp(19) : error C2228: la partie gauche de '.end' doit avoir un type class/struct/union le type est '' e:\Developpement\pimplib\pimplib_geometric_objects\src\../include\geometric_shape_factory.hpp(21) : error C2228: la partie gauche de '.insert' doit avoir un type class/struct/union le type est '' geometric_shape_factory.cpp Génération de code en cours... Temps de génération 0:01 Le journal de génération a été enregistré à l'emplacement "file://e:\Developpement\pimplib\pimplib_geometric_objects\Release\BuildLog.htm" pimplib_geometric_objects - 6 erreur(s), 0 avertissement(s)
D'avance merci.
Partager