Hi,
I want to use max_element with a predicate. I have 2 vectors stored in a class and I want to use min_element on one vector using a predicate which refers to the second. i.e. the first vector (seeds) holds indices referring to values in the second (nodes).
where Xlesser is defined byCode:unsigned int Map::GetSeed() { unsigned int seed = 0; if(seeds.size() > 1) { std::vector<unsigned int>::iterator iter; iter = std::min_element(seeds.begin(),seeds.end(), XLesser); seed = *iter; seeds.erase(iter); return seed; } if(seeds.size() == 1) { seed = seeds[0]; seeds.erase(seeds.begin()); return seed; } return seed; }
My problem is that predicates are meant to have 2 arguments but XLesser will have 3 (the 3rd being a pointer to the object). I've read that this can be overcome by declaring XLesser as static but that doesn't work here because XLesser accesses the private vector nodes and I get error C2597: illegal reference to non-static member 'Map::nodes'! How do I get around this!?Code:bool Map::XLesser(unsigned int index1, unsigned int index2) { return nodes[index1].x < nodes[index2].x; }
For some explanation nodes holds vertices and seeds holds indices referring to certain vertices in nodes.




Reply With Quote