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

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -