Bonjour tout le monde!
Je suis face à un problème que je ne m'explique pas: j'ai créé une std::map de la manière suivante:
Avec comme structure BandComparator:
Code : Sélectionner tout - Visualiser dans une fenêtre à part std::map<boost::shared_ptr<Band>, std::vector<boost::shared_ptr<Request> >, BandComparator >
Lorsque je tente de récupérer une valeur de la façon suivante, j'obtiens une erreur de segmentation:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 struct BandComparator { bool operator()(const Band& band1, const Band& band2) const; bool operator()(boost::shared_ptr<Band> band1, boost::shared_ptr<Band> band2) const; };
J'ai vérifié si la surcharge de l'opérateur de comparaison était correcte et aucun problème de ce niveau là.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 const std::vector<boost::shared_ptr<Request> >& BandAndRequestManager::getRequestsFromBand( const boost::shared_ptr<Band> &band) { return m_bandRequestsMap.at(band); }
De plus le groupe est bien trouvé (j'ai également utilisé la méthode find pour vérifier...)
Je ne comprends pas d'où mon erreur peut venir.
Si vous avez des idées, je suis preneur.
Merci.
Edit:
J'ai fait un code minimaliste qui reproduit le même comportement:
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 class Object { double m_d; int m_i; public: Object(): m_d(0.0), m_i(0){}; ~Object(){}; }; struct ObjectCompare { bool operator()(const boost::shared_ptr<Object>& obj1, const boost::shared_ptr<Object>& obj2) const { return true; } bool operator()(const Object& obj1, const Object& obj2) const { return true; } }; int main(int argc, char *argv[]) { std::map<boost::shared_ptr<Object>, std::vector<boost::shared_ptr<Object> >, ObjectCompare> map1; std::vector<boost::shared_ptr<Object> > vec1; vec1.push_back(boost::shared_ptr<Object>(new Object())); vec1.push_back(boost::shared_ptr<Object>(new Object())); vec1.push_back(boost::shared_ptr<Object>(new Object())); boost::shared_ptr<Object> object = boost::make_shared<Object>(); map1[object] = vec1; std::cout << "vec1.size(): " << vec1.size() << std::endl; //Aucun probleme std::cout << "map1.size(): " << map1.size() << std::endl; //Me retourne bien 1. std::cout << "map1.count(object): " << map1.count(object) << std::endl; //Me retourne 0... alors que je devrais obtenir 1; std::vector<boost::shared_ptr<Object> > vec2 = map1.at(object); //Erreur de segmentation std::cout << "vec2.size(): " << vec2.size() << std::endl; return 0; }
Partager