c++ - How can I write a function that, given a pointer to a map, returns a pointer to a specific element in the map? -
i have map:
std::map<int,float> m1;
i want pass pointer map function iterate on map , return pointer particular element in map based on condition.
float *foo(map<int,float> *m1){ float *result; for(map<int,float>::iterator = m1->begin(); != m1->end(); it++) { if (condition) { result = &(it->second); break; } } return result; }
this code did not compile. i'm having trouble seeing pointer , isn't. how passing pointer map affect iterator loop ?
thanks!
don't write own function, use standard library : std::find_if
looking :
auto = std::find_if (m1.begin(), m1.end(), testfunction); if(it != m1.end()) ...
Comments
Post a Comment