Take the following as a example: (Note, the example doesn't work, but it should be enough to illustrate what I am trying to do)
class Point {
float x, y;
public:
float getX() const { return x; }
float getY() const { return y; }
};
class Polygon {
std::vector<Point> points;
std::vector<float> get(float (Point::*func)()const) {
std::vector<float> ret;
for(std::vector<Point>::iterator it = points.begin(); it != points.end(); it++) {
// call the passed function on the actual instance
ret.push_back(it->*func());
}
return ret;
}
public:
std::vector<float> getAllX() const {
return get(&Point::getX); // <- what to pass for getX
}
std::vector<float> getAllY() const {
return get(&Point::getY); // <- what to pass for getY
}
};
EDIT:
The problem was order of operations; the compiler required parenthesis around the call as such:
(it->*func)()