c++ - Inserting values from Vector to Map -
c++ - Inserting values from Vector to Map -
i got issues trying set values of vector in new map (mamap) if explain me contain itemiterator or how do...
map<std::string,employee*> entreprise::convertivectormap() const { map<std::string,employee*> mamap; vector<employee*>::const_iterator itemiterator; for(itemiterator = vector_employe.begin(); itemiterator != vector_employe.end(); itemiterator++) { mamap.insert(std::pair<string,employee*>(itemiterator->getnom(),itemiterator)); } }
your map of <std::string, employee*>
, trying add together iterator sec element of pair
. need dereference iterator employee
pointer.
mamap.insert(std::pair<string,employee*>((*itemiterator)->getnom(), *itemiterator));
or save dereferencing same iterator twice, utilize range based for
loop. @captainobvlious mentions, can utilize std::make_pair
add together map
.
for(auto const employee: vector_employe) { mamap.insert(std::make_pair(employee->getnom(), employee)); }
c++ vector map
Comments
Post a Comment