std::map shared_ptr en cl� et std::vector <shared_ptr> en valeur
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:
Code:
std::map<boost::shared_ptr<Band>, std::vector<boost::shared_ptr<Request> >, BandComparator >
Avec comme structure BandComparator:
Code:
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;
}; |
Lorsque je tente de r�cup�rer une valeur de la fa�on suivante, j'obtiens une erreur de segmentation:
Code:
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);
} |
J'ai v�rifi� si la surcharge de l'op�rateur de comparaison �tait correcte et aucun probl�me de ce niveau l�.
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:
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;
} |